А что, MSDN уже не рулит ?
http://msdn.microsoft.com/library/rus/default.asp?url=/library/RUS/cpguide/html/cpconusingblockingserversocket.asp
| Код | Console.WriteLine("Waiting for a connection..."); Socket handler = listener.Accept(); String data = null;
while (true) { bytes = new byte[1024]; int bytesRec = handler.Receive(bytes); data += Encoding.ASCII.GetString(bytes,0,bytesRec); if (data.IndexOf("<EOF>") > -1) { break; } }
Console.WriteLine( "Text received : {0}", data);
byte[] msg = Encoding.ASCII.GetBytes(data); handler.Send(msg); handler.Shutdown(SocketShutdown.Both); handler.Close();
| |