// 连接的客户端 static void socketp2_SocketConnected(Socket sock) { // 创建新的线程来处理客户会话 new Thread( new ThreadStart(delegate { // 初始化套接字客户端 var client = new SocketClient(sock); try { client.MessageReceived += new EventHandler <SocketMessageEventArgs>(client_MessageReceived); client.MessageSended += new EventHandler <SocketMessageEventArgs>(client_MessageSended); // 准备接收 client.StartReceiving(); Console.WriteLine("客户端已连接!"); } catch (Exception ex) { Console.WriteLine("当开始接收消息时发生异常:\n" + ex.Message); client.Close(); } })).Start(); }
// Client connected static void socketp2_SocketConnected(Socket sock) { // Create new thread to handle client communication new Thread( new ThreadStart(delegate { // Initialize SocketClient var client = new SocketClient(sock); try { client.MessageReceived += new EventHandler <SocketMessageEventArgs>(client_MessageReceived); client.MessageSended += new EventHandler <SocketMessageEventArgs>(client_MessageSended); // Ready to receive client.StartReceiving(); Console.WriteLine("Client connected."); } catch (Exception ex) { Console.WriteLine("Exception occured when start receiving message:\n" + ex.Message); client.Close(); } })).Start(); }
// 连接的客户端 static void socketp2_SocketConnected(Socket sock) { // 创建新的线程来处理客户会话 new Thread( new ThreadStart(delegate { // 初始化套接字客户端 var client = new SocketClient(sock); try { client.MessageReceived += new EventHandler<SocketMessageEventArgs>(client_MessageReceived); client.MessageSended += new EventHandler<SocketMessageEventArgs>(client_MessageSended); // 准备接收 client.StartReceiving(); Console.WriteLine("客户端已连接!"); } catch (Exception ex) { Console.WriteLine("当开始接收消息时发生异常:\n" + ex.Message); client.Close(); } })).Start(); }