コード例 #1
0
        private void RunListenerSubscriber(IConnectionStubListener <SimpleMessage <int>, int> listener)
        {
            var stub = listener.AcceptNext();

            Console.WriteLine(@"Server: Got Connection");
            var connection = new StubConnection <SimpleMessage <int>, int>(
                new ThreadManager(), stub);
            var messages = 0;

            connection.Subscribe(1, (message, size) =>
            {
                TextMessageHandler("Server", message, size);
                messages++;
            });
            var exit = false;

            connection.Subscribe(2, (message, size) =>
            {
                Console.WriteLine(@"Received exit Message");
                Console.WriteLine(@"Total messages received: {0}", messages);
                exit = true;
            });
            connection.Send(new SimpleMessage <int>(0));
            while (!exit)
            {
                Thread.CurrentThread.Join(10);
            }
            connection.Disconnect();
            listener.Close();
        }
コード例 #2
0
        private void AcceptSocket(IConnectionStubListener <SimpleMessage <int>, int> listener)
        {
            Console.WriteLine(@"Server: Listening for connection");
            var remoteConnection = listener.AcceptNext();

            Console.WriteLine(@"Server: Got connection, closing listener");
            int read;

            Console.WriteLine(@"Server: Waiting for message");
            var msg = remoteConnection.ReadNext(out read);

            if (null == msg)
            {
                Console.WriteLine(@"Received null from connection");
                remoteConnection.Dispose();
                return;
            }
            Console.WriteLine(@"Server: Read {0} bytes", read);
            Console.WriteLine(@"Server: Message received; contents: {0}", Encoding.ASCII.GetString(msg.Data));
            Console.WriteLine(@"Server: Sending response");
            remoteConnection.Write(new SimpleMessage <int>(0, Encoding.ASCII.GetBytes("Hello to you too")));
            Console.WriteLine(@"Server: Done, exiting");
            remoteConnection.Dispose();
            listener.Close();
        }
コード例 #3
0
 public void Stop()
 {
     if (!isStarted)
     {
         return;
     }
     isStarted = false;
     listener.Close();
     connectionWorker.Wait();
     connectionWorker = null;
 }
コード例 #4
0
 private void RunListenerSubscriber(IConnectionStubListener<SimpleMessage<int>, int> listener)
 {
     var stub = listener.AcceptNext();
     Console.WriteLine(@"Server: Got Connection");
     var connection = new StubConnection<SimpleMessage<int>, int>(
         new ThreadManager(), stub);
     var messages = 0;
     connection.Subscribe(1, (message, size) =>
     {
         TextMessageHandler("Server", message, size);
         messages++;
     });
     var exit = false;
     connection.Subscribe(2, (message, size) =>
     {
         Console.WriteLine(@"Received exit Message");
         Console.WriteLine(@"Total messages received: {0}", messages);
         exit = true;
     });
     connection.Send(new SimpleMessage<int>(0));
     while (!exit)
     {
         Thread.CurrentThread.Join(10);
     }
     connection.Disconnect();
     listener.Close();
 }
コード例 #5
0
 private void AcceptSocket(IConnectionStubListener<SimpleMessage<int>, int> listener)
 {
     Console.WriteLine(@"Server: Listening for connection");
     var remoteConnection = listener.AcceptNext();
     Console.WriteLine(@"Server: Got connection, closing listener");
     int read;
     Console.WriteLine(@"Server: Waiting for message");
     var msg = remoteConnection.ReadNext(out read);
     if (null == msg)
     {
         Console.WriteLine(@"Received null from connection");
         remoteConnection.Dispose();
         return;
     }
     Console.WriteLine(@"Server: Read {0} bytes", read);
     Console.WriteLine(@"Server: Message received; contents: {0}", Encoding.ASCII.GetString(msg.Data));
     Console.WriteLine(@"Server: Sending response");
     remoteConnection.Write(new SimpleMessage<int>(0, Encoding.ASCII.GetBytes("Hello to you too")));
     Console.WriteLine(@"Server: Done, exiting");
     remoteConnection.Dispose();
     listener.Close();
 }