# HG changeset patch # User riono # Date 1606992798 -32400 # Node ID 970c7f587126f05840a6cf4a7b24cb2c7548ced3 # Parent d488eb23a29f010fe4c8214c472f1614f7ad414f update AcceptThread diff -r d488eb23a29f -r 970c7f587126 Christie_net.csproj --- a/Christie_net.csproj Thu Dec 03 19:04:33 2020 +0900 +++ b/Christie_net.csproj Thu Dec 03 19:53:18 2020 +0900 @@ -3,7 +3,7 @@ Exe netcoreapp3.1 - SocketLisnerThread + SocketListenerTask diff -r d488eb23a29f -r 970c7f587126 Test/RewritingTest/SocketLisnerThread.cs --- a/Test/RewritingTest/SocketLisnerThread.cs Thu Dec 03 19:04:33 2020 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Text; -using System.Threading; - -public class SocketLisnerThread { - Socket socket; - - public SocketLisnerThread (Socket socket) { - this.socket = socket; - } - - public void Run () { - Thread thread = new Thread (new ThreadStart (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); - // } - - SocketLisnerThread newThread = new SocketLisnerThread (ss); - newThread.Run (); - - // Console.WriteLine("fin"); - // listener.Shutdown(SocketShutdown.Both); - // listener.Close(); - } catch (Exception e) { - Console.WriteLine (e.ToString ()); - } - - } -} \ No newline at end of file diff -r d488eb23a29f -r 970c7f587126 Test/RewritingTest/SocketListenerTask.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test/RewritingTest/SocketListenerTask.cs Thu Dec 03 19:53:18 2020 +0900 @@ -0,0 +1,54 @@ +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using System.Threading.Tasks; + + +public class SocketListenerTask { + Socket socket; + + public SocketListenerTask (Socket socket) { + this.socket = socket; + } + + public void Run () { + // Thread thread = new Thread (new ThreadStart (MethodThread)); + // thread.Start(); + Task task = Task.Run((() => MethodThread())); + } + + 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 ()); + } + + } +} diff -r d488eb23a29f -r 970c7f587126 Test/RewritingTest/SocketListenerThread.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test/RewritingTest/SocketListenerThread.cs Thu Dec 03 19:53:18 2020 +0900 @@ -0,0 +1,53 @@ +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 (new ThreadStart (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 ()); + } + + } +} \ No newline at end of file diff -r d488eb23a29f -r 970c7f587126 daemon/AcceptThread.cs --- a/daemon/AcceptThread.cs Thu Dec 03 19:04:33 2020 +0900 +++ b/daemon/AcceptThread.cs Thu Dec 03 19:53:18 2020 +0900 @@ -1,4 +1,31 @@ +using System; +using System.Net; +using System.Net.Sockets; +using Christie_net.codegear; + namespace Christie_net.daemon { public class AcceptThread { + private Socket soc; + public int counter = 0; + public CodeGearManager cgm; + + public AcceptThread(Socket soc, CodeGearManager cgm) { + this.soc = soc; + this.cgm = cgm; + } + + public void Run() { + while (true) { + try { + Socket socket = null; + socket = soc.Accept(); + Console.WriteLine("Accept " + socket.LocalEndPoint + ":" + ((IPEndPoint)socket.LocalEndPoint).Port); + string key = "accept" + counter; + + } catch (Exception e) { + + } + } + } } } \ No newline at end of file diff -r d488eb23a29f -r 970c7f587126 daemon/Connection.cs --- a/daemon/Connection.cs Thu Dec 03 19:04:33 2020 +0900 +++ b/daemon/Connection.cs Thu Dec 03 19:53:18 2020 +0900 @@ -30,8 +30,8 @@ /// /// public string GetInfoString() { - return (Dns.GetHostEntry(((IPEndPoint) socket.RemoteEndPoint).Address.ToString()).HostName + ":" + - ((IPEndPoint) socket.RemoteEndPoint).Port.ToString()); + return Dns.GetHostEntry(((IPEndPoint) socket.LocalEndPoint).Address.ToString()).HostName + ":" + + ((IPEndPoint) socket.LocalEndPoint).Port; } ///