Mercurial > hg > Database > Christie-sharp
view daemon/AcceptThread.cs @ 29:0cd2684e401b
update InputDataGear and more
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 21 Jan 2021 01:18:26 +0900 |
parents | 45ff08d59fda |
children | 6399d784c6d1 |
line wrap: on
line source
using System; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; using Christie_net.codegear; namespace Christie_net.daemon { public class AcceptThread { private Socket soc; public int counter = 0; public CodeGearManager cgm; public AcceptThread(Socket soc, CodeGearManager cgm) { this.soc = soc; this.cgm = cgm; } public void Run() { while (true) { try { Socket socket = null; socket = soc.Accept(); socket.NoDelay = true; Console.WriteLine("Accept " + socket.LocalEndPoint + ":" + ((IPEndPoint)socket.LocalEndPoint).Port); Connection connection = new Connection(socket, cgm); string key = "accept" + counter; IncomingTcpConnection incoming = new IncomingTcpConnection(connection); Task.Factory.StartNew( () => incoming.Run(), TaskCreationOptions.LongRunning); cgm.SetAccept(key, incoming); OutboundTcpConnection outbound = new OutboundTcpConnection(connection); Task.Factory.StartNew( () => outbound.Run(), TaskCreationOptions.LongRunning); counter++; } catch (Exception e) { Console.WriteLine(e.StackTrace); } } } } }