Esempio n. 1
0
 public void SetUp()
 {
     Listener = new TcpListener(IPAddress.Any, 1235);
     Listener.Start();
     var fA = Listener.AcceptIncomingConnection();
     var fB = Network.ConnectTo("localhost", 1235);
     fA.GetCompletionEvent().Wait();
     A = fA.Result as TcpClient;
     fB.GetCompletionEvent().Wait();
     B = fB.Result as TcpClient;
     Listener.Stop();
     StreamA = A.GetStream();
     StreamB = B.GetStream();
 }
Esempio n. 2
0
        static IEnumerator<object> AcceptConnectionsTask (TcpListener server) {
            server.Start();
            try {
                int nextId = 0;
                while (true) {
                    var connection = server.AcceptIncomingConnection();
                    yield return connection;

                    Peer peer = new Peer { PeerId = nextId++ };
                    TcpClient client = connection.Result as TcpClient;
                    client.Client.Blocking = false;
                    var peerTask = PeerTask(client, peer);
                    Scheduler.Start(peerTask, TaskExecutionPolicy.RunAsBackgroundTask);
                }
            } finally {
                server.Stop();
            }
        }