コード例 #1
0
 public void Send(String message)
 {
     try
     {
         message += "#<<<!!!EOF!!!>>>";
         ClientSendMessage obj = new ClientSendMessage {
             message = message, socket = socket
         };
         Console.WriteLine(obj.message);
         sendBuffer = Encoding.ASCII.GetBytes(message);
         socket.BeginSend(sendBuffer, 0, sendBuffer.Length, 0, new AsyncCallback(SendCallback), obj);
     }
     catch (Exception)
     {
         //MessageBox.Show("9. Exception:\t\n" + exc.Message.ToString());
     }
 }
コード例 #2
0
 private void SendCallback(IAsyncResult ar)
 {
     try
     {
         ClientSendMessage obj = (ClientSendMessage)ar.AsyncState;
         int bytesSent         = obj.socket.EndSend(ar);
         Console.WriteLine("Sent " + bytesSent + " bytes to the client");
         if (obj.message == "r")
         {
             try
             {
                 socket.Shutdown(SocketShutdown.Both);
                 socket.Close();
             }
             catch (Exception) { }
         }
     }
     catch (Exception exc)
     {
         MessageBox.Show("10. Exception:\t\n" + exc.Message.ToString());
     }
 }