예제 #1
0
 // 使用套接字客户端发送消息
 static void SendMessage(SocketClient client, string data)
 {
     try
     {
         client.SendAsync(data);
     }
     catch (Exception ex)
     {
         Console.WriteLine("当发送消息时,发生异常:\n" + ex.Message);
         client.Close();
         Console.WriteLine("客户端断开连接。");
     }
 }
예제 #2
0
파일: Program.cs 프로젝트: thexur/1code
 // User SocketClient to send message
 static void SendMessage(SocketClient client, string data)
 {
     try
     {
         client.SendAsync(data);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Exception occured when sending message:\n" + ex.Message);
         client.Close();
         Console.WriteLine("Client disconnected.");
     }
 }
예제 #3
0
 // 连接的客户端
 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();
 }
예제 #4
0
파일: Program.cs 프로젝트: thexur/1code
 // 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();
 }
예제 #5
0
 // 使用套接字客户端发送消息
 static void SendMessage(SocketClient client, string data)
 {
     try
     {
         client.SendAsync(data);
     }
     catch (Exception ex)
     {
         Console.WriteLine("当发送消息时,发生异常:\n" + ex.Message);
         client.Close();
         Console.WriteLine("客户端断开连接。");
     }
 }
예제 #6
0
 // 连接的客户端
 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();
 }