Mercurial > hg > Database > Christie-sharp
view daemon/AcceptThread.cs @ 56:dc3f59937772
remote dynamic
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 25 Jan 2022 16:46:26 +0900 (2022-01-25) |
parents | 98ee1ee1efb7 |
children | 12b7528000da |
line wrap: on
line source
using System; using System.Net; using System.Net.Sockets; using System.Threading; using Christie_net.codegear; namespace Christie_net.daemon { public class AcceptThread { private TcpListener listener; public int counter = 0; public CodeGearManager cgm; public AcceptThread(TcpListener listener, CodeGearManager cgm) { this.listener = listener; this.cgm = cgm; } public void Run() { try { TcpClient client = null; client = listener.AcceptTcpClient(); client.NoDelay = true; IPEndPoint endPoint = (IPEndPoint) client.Client.RemoteEndPoint; IPAddress ipAddress = endPoint.Address; IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); Console.WriteLine("Accept " + hostEntry.HostName + ":" + endPoint.Port); Connection connection = new Connection(client.Client, cgm); Console.WriteLine("connection:" + connection.GetInfoString()); string key = "accept" + counter; IncomingTcpConnection incoming = new IncomingTcpConnection(connection); Thread incomingThread = new Thread(incoming.Run); incomingThread.Name = connection.GetInfoString() + "-IncomingTcp"; incomingThread.Start(); cgm.SetAccept(key, incoming); OutboundTcpConnection outbound = new OutboundTcpConnection(connection); Thread outboundThread = new Thread(outbound.Run); outboundThread.Name = connection.GetInfoString() + "-OutboundTcp"; outboundThread.Start(); counter++; } catch (Exception e) { Console.WriteLine(e.StackTrace); } } } }