| using System.Net;
|
| using System.Net.Sockets;
|
| using System.Text;
|
|
|
| IPAddress ip = IPAddress.Parse("127.0.0.1");
|
| IPEndPoint ep = new IPEndPoint(ip, 1024);
|
| Socket s = new Socket(AddressFamily.InterNetwork,
|
| SocketType.Stream, ProtocolType.IP);
|
| s.Bind(ep);
|
| s.Listen(10);
|
|
|
| try
|
| {
|
| while (true)
|
| {
|
| Socket ns = s.Accept();
|
| Console.WriteLine(ns.RemoteEndPoint.ToString());
|
| ns.Send(Encoding.ASCII.GetBytes(DateTime.Now.ToString()));
|
| ns.Shutdown(SocketShutdown.Both);
|
| ns.Close();
|
| }
|
| }
|
| catch (SocketException ex)
|
| {
|
| Console.WriteLine(ex.Message);
|
| }
|