# HG changeset patch # User riono # Date 1606989873 -32400 # Node ID d488eb23a29f010fe4c8214c472f1614f7ad414f # Parent 3aaa77e124934469972411d23126e0c662178167 add ThreadTest diff -r 3aaa77e12493 -r d488eb23a29f Christie_net.csproj --- a/Christie_net.csproj Tue Dec 01 20:23:09 2020 +0900 +++ b/Christie_net.csproj Thu Dec 03 19:04:33 2020 +0900 @@ -3,7 +3,7 @@ Exe netcoreapp3.1 - EnumInit + SocketLisnerThread diff -r 3aaa77e12493 -r d488eb23a29f Test/RewritingTest/CreateThread.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test/RewritingTest/CreateThread.cs Thu Dec 03 19:04:33 2020 +0900 @@ -0,0 +1,41 @@ +using System; +using System.Threading; + +public class CreateThread { + public static void Main () { + Console.WriteLine ("スタート"); + + // DoSomethingメソッドを別のスレッドで実行するThreadオブジェクトを作成する + //Thread t = new Thread (new ThreadStart (DoSomething)); + // スレッドを開始する + //t.Start (); + + //t.IsBackground = true; + + //t.Join (); + + CreateThread createThread = new CreateThread(); + createThread.Run(); + + Console.WriteLine ("Enterキーを押してください"); + Console.ReadLine (); + } + + public void Run() { + Thread thread = new Thread(DoSomething); + thread.Start(); + thread.Join(); + } + + // 別スレッドで実行するメソッド + private static void DoSomething () { + // 長い時間のかかる処理があるものとする + for (long i = 0; i < 1000000; i++) { + Console.Write("1"); + } + + // 処理が終わったことを知らせる + Console.WriteLine ("終わりました"); + } +} + diff -r 3aaa77e12493 -r d488eb23a29f Test/RewritingTest/SocketLisnerThread.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test/RewritingTest/SocketLisnerThread.cs Thu Dec 03 19:04:33 2020 +0900 @@ -0,0 +1,53 @@ +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 3aaa77e12493 -r d488eb23a29f daemon/AcceptThread.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/daemon/AcceptThread.cs Thu Dec 03 19:04:33 2020 +0900 @@ -0,0 +1,4 @@ +namespace Christie_net.daemon { +public class AcceptThread { +} +} \ No newline at end of file