最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)----使用方法
时间:2022-07-02 11:07:10 编辑:袖梨 来源:一聚教程网
一.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;
}
//运行服务器程序
相关文章
- 腾讯视频网页版入口在哪-腾讯视频网页版入口链接 02-10
- 歪歪漫画最新入口地址:2026年热门韩漫同步连载中 02-10
- 蛙漫2台版入口网页最新版-蛙漫2台版入口网页最新访问链接 02-10
- 创游世界网页版入口-创游世界网页版直达链接 02-10
- 12360火车票余票查询-如何在线查询火车票余票 02-10
- 抖音官网网页版入口-抖音网页版在线观看链接 02-10