"public class DMTcpServer : Component\n{\n\tpublic System.Net.Sockets.Socket ServerSocket; \n\tpublic Thread StartSockst; \n\tpublic bool IsStartListening; \n\tpublic List<System.Net.Sockets.Socket> ClientSocketList; \n\n\tpublic DMTcpServer(); \n\tpublic DMTcpServer(IContainer container); \n\n\t[Category("TCP服务端")] \n\t[Description("本机监听端口,默认是5000")] \n\tpublic int ServerPort { get; set; } \n\t[Category("TCP服务端")] \n\t[Description("本机监听IP,默认是本地IP")] \n\tpublic string ServerIp { get; set; } \n\n\t[Category("TcpServer事件")] \n\t[Description("用户上线下线时更新客户端在线数量事件")] \n\tpublic event ReturnClientCountEventHandler OnReturnClientCount; \n\t[Category("TcpServer事件")] \n\t[Description("错误消息")] \n\tpublic event ErrorMsgEventHandler OnErrorMsg; \n\t[Category("TcpServer事件")] \n\t[Description("接收原始Byte数组数据事件")] \n\tpublic event ReceviceByteEventHandler OnReceviceByte; \n\t[Category("TcpServer事件")] \n\t[Description("客户端下线时返回客户端事件")] \n\tpublic event AddClientEventHandler OnOfflineClient; \n\t[Category("TcpServer事件")] \n\t[Description("监听状态改变时返回监听状态事件")] \n\tpublic event StateInfoEventHandler OnStateInfo; \n\t[Category("TcpServer事件")] \n\t[Description("新客户端上线时返回客户端事件")] \n\tpublic event AddClientEventHandler OnOnlineClient; \n\n\tpublic void ClientSocketCallBack(object obj); \n\tpublic System.Net.Sockets.Socket ResoultSocket(string ip, int port); \n\tpublic void SendData(string ip, int port, byte[] dataBytes); \n\tpublic void SendData(string ip, int port, string strData); \n\tpublic void Start(); \n\tpublic void StartSocketListening(); \n\tpublic void Stop(); \n\tprotected override void Dispose(bool disposing); \n\tprotected virtual void OnTcpServerErrorMsgEnterHead(string msg); \n\tprotected virtual void OnTcpServerOfflineClientEnterHead(System.Net.Sockets.Socket temp); \n\tprotected virtual void OnTcpServerOnlineClientEnterHead(System.Net.Sockets.Socket temp); \n\tprotected virtual void OnTcpServerReceviceByte(System.Net.Sockets.Socket temp, byte[] dataBytes); \n\tprotected virtual void OnTcpServerReturnClientCountEnterHead(int count); \n\tprotected virtual void OnTcpServerStateInfoEnterHead(string msg, SocketState state); \n\n\tpublic delegate void ReceviceByteEventHandler(System.Net.Sockets.Socket temp, byte[] dataBytes); \n\tpublic delegate void ErrorMsgEventHandler(string msg); \n\tpublic delegate void ReturnClientCountEventHandler(int count); \n\tpublic delegate void StateInfoEventHandler(string msg, SocketState state); \n\tpublic delegate void AddClientEventHandler(System.Net.Sockets.Socket temp); \n\tpublic delegate void OfflineClientEventHandler(System.Net.Sockets.Socket temp); \n}

C# TCP Server Implementation: DMTcpServer Class

原文地址: https://www.cveoy.top/t/topic/p7Hs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录