// 处理消息发送事件 static void client_MessageSended(object sender, CSSL3SocketServer.SocketMessageEventArgs e) { if (e.Error != null) { Console.WriteLine("消息发送失败: " + e.Error.Message); ((SocketClient)sender).Close(); Console.WriteLine("客户端断开连接。"); } else { Console.WriteLine("消息发送成功!"); } }
// Handle message sended event static void client_MessageSended(object sender, CSSL3SocketServer.SocketMessageEventArgs e) { if (e.Error != null) { Console.WriteLine("Message send failed: " + e.Error.Message); ((SocketClient)sender).Close(); Console.WriteLine("Client disconnected."); } else { Console.WriteLine("Message send successful"); } }
// 处理消息接收事件 static void client_MessageReceived(object sender, CSSL3SocketServer.SocketMessageEventArgs e) { if (e.Error != null) { Console.WriteLine("消息接收失败: " + e.Error.Message); ((SocketClient)sender).Close(); Console.WriteLine("客户端断开连接。"); } else { // 等待1秒后,回发消息 Console.WriteLine("收到消息: " + e.Data); Thread.Sleep(1000); SendMessage(sender as SocketClient, "处理: " + e.Data); } }
// Handle message received event static void client_MessageReceived(object sender, CSSL3SocketServer.SocketMessageEventArgs e) { if (e.Error != null) { Console.WriteLine("Message receive failed: " + e.Error.Message); ((SocketClient)sender).Close(); Console.WriteLine("Client disconnected."); } else { // Idle 1 second and send message back Console.WriteLine("Message Received: " + e.Data); Thread.Sleep(1000); SendMessage(sender as SocketClient, "Handled: " + e.Data); } }