Mercurial > hg > Database > Christie-sharp
annotate daemon/AcceptThread.cs @ 34:1236da135f79
update
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 27 Apr 2021 22:57:14 +0900 |
parents | 7575980bffc9 |
children | 98ee1ee1efb7 |
rev | line source |
---|---|
22 | 1 using System; |
2 using System.Net; | |
3 using System.Net.Sockets; | |
33 | 4 using System.Threading; |
22 | 5 using Christie_net.codegear; |
6 | |
21 | 7 namespace Christie_net.daemon { |
8 public class AcceptThread { | |
33 | 9 private TcpListener listener; |
22 | 10 public int counter = 0; |
11 public CodeGearManager cgm; | |
12 | |
33 | 13 public AcceptThread(TcpListener listener, CodeGearManager cgm) { |
14 this.listener = listener; | |
22 | 15 this.cgm = cgm; |
16 } | |
17 | |
18 public void Run() { | |
34 | 19 while (true) { |
22 | 20 try { |
33 | 21 TcpClient client = null; |
22 client = listener.AcceptTcpClient(); | |
23 client.NoDelay = true; | |
24 | |
25 IPEndPoint endPoint = (IPEndPoint) client.Client.RemoteEndPoint; | |
26 IPAddress ipAddress = endPoint.Address; | |
27 IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); | |
28 Console.WriteLine("Accept " + hostEntry.HostName + ":" + endPoint.Port); | |
29 | |
30 Connection connection = new Connection(client.Client, cgm); | |
22 | 31 string key = "accept" + counter; |
32 | |
26 | 33 IncomingTcpConnection incoming = new IncomingTcpConnection(connection); |
33 | 34 Thread incomingThread = new Thread(incoming.Run); |
35 incomingThread.Name = connection.GetInfoString() + "-IncomingTcp"; | |
36 incomingThread.Start(); | |
37 | |
29
0cd2684e401b
update InputDataGear and more
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
26
diff
changeset
|
38 cgm.SetAccept(key, incoming); |
34 | 39 |
26 | 40 OutboundTcpConnection outbound = new OutboundTcpConnection(connection); |
33 | 41 Thread outboundThread = new Thread(outbound.Run); |
42 outboundThread.Name = connection.GetInfoString() + "-OutboundTcp"; | |
43 outboundThread.Start(); | |
25 | 44 counter++; |
22 | 45 } catch (Exception e) { |
25 | 46 Console.WriteLine(e.StackTrace); |
22 | 47 } |
34 | 48 } |
22 | 49 } |
21 | 50 } |
51 } |