Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. private static void ReceiveCallback(IAsyncResult AR)
  2.         {
  3.             Socket socket = (Socket)AR.AsyncState;
  4.             try
  5.             {
  6.                 int received = socket.EndReceive(AR);
  7.  
  8.                 byte[] dataBuf = new byte[received];
  9.                 Array.Copy(_buffer, dataBuf, received);
  10.  
  11.                 string text = Encoding.ASCII.GetString(dataBuf);
  12.                 Console.Write("Gauta: " + text);
  13.  
  14.                 string response = string.Empty;
  15.  
  16.                 if (text.ToLower() != "time")
  17.                 {
  18.                     response = "Neteisinga uzklausa";
  19.                 }
  20.                 else
  21.                 {
  22.                     response = DateTime.Now.ToLongTimeString();
  23.  
  24.                 }
  25.  
  26.                 byte[] data = Encoding.ASCII.GetBytes(response);
  27.                 socket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), socket);
  28.             }
  29.             catch (Exception)
  30.             {
  31.                 //string _clientIP = socket.RemoteEndPoint.ToString();
  32.                 //Console.WriteLine("Client Disconnected [" + _clientIP + " ]");
  33.             }
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement