Mercurial > hg > Database > Christie-sharp
view Test/RewritingTest/SocketListenerThread.cs @ 33:7575980bffc9
update
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 20 Apr 2021 18:42:17 +0900 |
parents | 970c7f587126 |
children |
line wrap: on
line source
using System; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; public class SocketListenerThread { Socket socket; public SocketListenerThread (Socket socket) { this.socket = socket; } public void Run () { Thread thread = new Thread (MethodThread); thread.Start(); } private void MethodThread() { Socket listener = socket.Accept (); while (true) { Console.WriteLine ("Accept:" + listener.LocalEndPoint); Thread.Sleep(1000); } } public static void Main () { IPHostEntry host = Dns.GetHostEntry ("localhost"); IPAddress ipAddress = host.AddressList[0]; IPEndPoint localEndPoint = new IPEndPoint (ipAddress, 11000); try { Socket ss = new Socket (ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); ss.Bind(localEndPoint); ss.Listen(10); // while (true) { // Console.WriteLine("Accept:" + listener.LocalEndPoint); // } SocketListenerThread newThread = new SocketListenerThread (ss); newThread.Run (); // Console.WriteLine("fin"); // listener.Shutdown(SocketShutdown.Both); // listener.Close(); } catch (Exception e) { Console.WriteLine (e.ToString ()); } } }