22
|
1 using System;
|
|
2 using System.Net;
|
|
3 using System.Net.Sockets;
|
25
|
4 using System.Threading.Tasks;
|
22
|
5 using Christie_net.codegear;
|
|
6
|
21
|
7 namespace Christie_net.daemon {
|
|
8 public class AcceptThread {
|
22
|
9 private Socket soc;
|
|
10 public int counter = 0;
|
|
11 public CodeGearManager cgm;
|
|
12
|
|
13 public AcceptThread(Socket soc, CodeGearManager cgm) {
|
|
14 this.soc = soc;
|
|
15 this.cgm = cgm;
|
|
16 }
|
|
17
|
|
18 public void Run() {
|
|
19 while (true) {
|
|
20 try {
|
26
|
21 Socket socket = null;
|
|
22 socket = soc.Accept();
|
25
|
23 socket.NoDelay = true;
|
22
|
24 Console.WriteLine("Accept " + socket.LocalEndPoint + ":" + ((IPEndPoint)socket.LocalEndPoint).Port);
|
25
|
25
|
|
26 Connection connection = new Connection(socket, cgm);
|
22
|
27 string key = "accept" + counter;
|
|
28
|
26
|
29 IncomingTcpConnection incoming = new IncomingTcpConnection(connection);
|
|
30 Task.Factory.StartNew(
|
|
31 () => incoming.Run(),
|
|
32 TaskCreationOptions.LongRunning);
|
25
|
33 //cgm.SetAccept(key, in);
|
|
34
|
26
|
35 OutboundTcpConnection outbound = new OutboundTcpConnection(connection);
|
|
36 Task.Factory.StartNew(
|
|
37 () => outbound.Run(),
|
|
38 TaskCreationOptions.LongRunning);
|
25
|
39 counter++;
|
22
|
40 } catch (Exception e) {
|
25
|
41 Console.WriteLine(e.StackTrace);
|
22
|
42 }
|
|
43 }
|
|
44 }
|
21
|
45 }
|
|
46 } |