Mercurial > hg > Database > Christie-sharp
view daemon/AcceptThread.cs @ 45:98ee1ee1efb7
error message is change
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 30 Nov 2021 19:34:24 +0900 |
parents | 1236da135f79 |
children | dc3f59937772 |
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() { while (true) { 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); } } } } }