最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)----使用方法
时间:2008-01-12 编辑:简简单单 来源:一聚教程网
一.TcpSvr的使用方法
A.测试程序:
using System;
using Ibms.Net.TcpCSFramework;
using System.Collections;
using System.Net.Sockets;
namespace Ibms.Test
{
///
/// 测试TcpSvr的类
///
public class TestTcpSvr
{
public TestTcpSvr()
{
}
public static void Main()
{
try
{
Console.WriteLine("Begin to Test TcpSvr class...");
TestTcpSvr tts = new TestTcpSvr();
//TcpSvr svr = new TcpSvr(9050,4);//默认使用Encoding.Default编码方式
TcpSvr svr = new TcpSvr(9050,4,new Coder(Coder.EncodingMothord.UTF8));
svr.Resovlver = new DatagramResolver("##");
//定义服务器的4个事件
//服务器满
svr.ServerFull += new NetEvent(tts.ServerFull);
//新客户端连接
svr.ClientConn += new NetEvent(tts.ClientConn);
//客户端关闭
svr.ClientClose += new NetEvent(tts.ClientClose);
//接收到数据
svr.RecvData += new NetEvent(tts.RecvData);
//命令控制循环
while(true)
{
Console.Write(">");
string cmd=Console.ReadLine();
//退出测试程序
if(cmd.ToLower() == "exit")
{
break;
}
//停止服务器程序
if(cmd.ToLower() == "stop")
{
svr.Stop();
Console.WriteLine("Server is Stop.");
continue;
}
//运行服务器程序
A.测试程序:
using System;
using Ibms.Net.TcpCSFramework;
using System.Collections;
using System.Net.Sockets;
namespace Ibms.Test
{
///
/// 测试TcpSvr的类
///
public class TestTcpSvr
{
public TestTcpSvr()
{
}
public static void Main()
{
try
{
Console.WriteLine("Begin to Test TcpSvr class...");
TestTcpSvr tts = new TestTcpSvr();
//TcpSvr svr = new TcpSvr(9050,4);//默认使用Encoding.Default编码方式
TcpSvr svr = new TcpSvr(9050,4,new Coder(Coder.EncodingMothord.UTF8));
svr.Resovlver = new DatagramResolver("##");
//定义服务器的4个事件
//服务器满
svr.ServerFull += new NetEvent(tts.ServerFull);
//新客户端连接
svr.ClientConn += new NetEvent(tts.ClientConn);
//客户端关闭
svr.ClientClose += new NetEvent(tts.ClientClose);
//接收到数据
svr.RecvData += new NetEvent(tts.RecvData);
//命令控制循环
while(true)
{
Console.Write(">");
string cmd=Console.ReadLine();
//退出测试程序
if(cmd.ToLower() == "exit")
{
break;
}
//停止服务器程序
if(cmd.ToLower() == "stop")
{
svr.Stop();
Console.WriteLine("Server is Stop.");
continue;
}
//运行服务器程序
-
上一个: asp.net的用户控件心得
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- C语言中atoi函数模拟实现介绍 10-18
- C#中ArrayList 类的使用介绍 09-22
- C#非托管泄漏中HEAP_ENTRY的Size对不上解析问题解决方法 09-22
- C#序列化与反序列化集合对象并进行版本控制的方法 09-19
- C#枚举高级战术代码解析 10-13