/// <summary> /// 构造函数 /// </summary> /// <param name="iPAddress">要监听的客户端通信IP</param> /// <param name="Port">要监听的客户端通信端口</param> public Control(IPAddress iPAddress, Ports Port) { ListenIp = iPAddress; ListenPort = Port; ServerTcp = new Tcp(iPAddress, Port); // 实例化Tcp对象 ServerTcp.Conneter += Conneter; // 绑定收到连接委托 ServerTcp.ReceiveContext += Messager; // 绑定接收消息委托 ServerTcp.TcpError += ConnetError; // 绑定断开连接委托 ServerTcp.ListenStop += ListenStop; // 绑定监听停止方法 messageDis = new MessageDis(); // 实例化消息接受对象 messageDis.CompletePack += MessagePack; // 绑定包接收委托 }
/// <summary> /// 监听被停止 /// </summary> private void ListenStop() { if (ServerState == true) { ServerTcp.Stop(); ServerTcp = new Tcp(ListenIp, ListenPort); // 实例化Tcp对象 ServerTcp.Conneter += Conneter; // 绑定收到连接委托 ServerTcp.ReceiveContext += Messager; // 绑定接收消息委托 ServerTcp.TcpError += ConnetError; // 绑定断开连接委托 ServerTcp.ListenStop += ListenStop; // 绑定监听停止方法 messageDis = new MessageDis(); // 实例化消息接受对象 messageDis.CompletePack += MessagePack; // 绑定包接收委托 } }