comparison 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
comparison
equal deleted inserted replaced
33:7575980bffc9 34:1236da135f79
14 this.listener = listener; 14 this.listener = listener;
15 this.cgm = cgm; 15 this.cgm = cgm;
16 } 16 }
17 17
18 public void Run() { 18 public void Run() {
19 //while (true) { 19 while (true) {
20 try { 20 try {
21 TcpClient client = null; 21 TcpClient client = null;
22 client = listener.AcceptTcpClient(); 22 client = listener.AcceptTcpClient();
23 client.NoDelay = true; 23 client.NoDelay = true;
24 24
26 IPAddress ipAddress = endPoint.Address; 26 IPAddress ipAddress = endPoint.Address;
27 IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); 27 IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress);
28 Console.WriteLine("Accept " + hostEntry.HostName + ":" + endPoint.Port); 28 Console.WriteLine("Accept " + hostEntry.HostName + ":" + endPoint.Port);
29 29
30 Connection connection = new Connection(client.Client, cgm); 30 Connection connection = new Connection(client.Client, cgm);
31 Console.WriteLine("connect@" + connection.GetInfoString());
32 string key = "accept" + counter; 31 string key = "accept" + counter;
33 32
34 IncomingTcpConnection incoming = new IncomingTcpConnection(connection); 33 IncomingTcpConnection incoming = new IncomingTcpConnection(connection);
35 Thread incomingThread = new Thread(incoming.Run); 34 Thread incomingThread = new Thread(incoming.Run);
36 incomingThread.Name = connection.GetInfoString() + "-IncomingTcp"; 35 incomingThread.Name = connection.GetInfoString() + "-IncomingTcp";
37 incomingThread.Start(); 36 incomingThread.Start();
38 37
39 cgm.SetAccept(key, incoming); 38 cgm.SetAccept(key, incoming);
40 39
41 OutboundTcpConnection outbound = new OutboundTcpConnection(connection); 40 OutboundTcpConnection outbound = new OutboundTcpConnection(connection);
42 Thread outboundThread = new Thread(outbound.Run); 41 Thread outboundThread = new Thread(outbound.Run);
43 outboundThread.Name = connection.GetInfoString() + "-OutboundTcp"; 42 outboundThread.Name = connection.GetInfoString() + "-OutboundTcp";
44 outboundThread.Start(); 43 outboundThread.Start();
45 counter++; 44 counter++;
46 } catch (Exception e) { 45 } catch (Exception e) {
47 Console.WriteLine(e.StackTrace); 46 Console.WriteLine(e.StackTrace);
48 } 47 }
49 //} 48 }
50 } 49 }
51 } 50 }
52 } 51 }