Mercurial > hg > Database > Christie-sharp
changeset 22:970c7f587126
update AcceptThread
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Dec 2020 19:53:18 +0900 |
parents | d488eb23a29f |
children | 46cfeb0609c5 |
files | Christie_net.csproj Test/RewritingTest/SocketLisnerThread.cs Test/RewritingTest/SocketListenerTask.cs Test/RewritingTest/SocketListenerThread.cs daemon/AcceptThread.cs daemon/Connection.cs |
diffstat | 6 files changed, 137 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> - <StartupObject>SocketLisnerThread</StartupObject> + <StartupObject>SocketListenerTask</StartupObject> </PropertyGroup> <ItemGroup>
--- 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
--- /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 ()); + } + + } +}
--- /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
--- 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
--- 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 @@ /// </summary> /// <returns></returns> 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; } /// <summary>