Beispiel #1
0
 private static void TcpServer()
 {
     TcpListener listener = new TcpListener(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9900));
     listener.Start(1);
     var tcpClient = listener.AcceptTcpClient();
     using (var stream = tcpClient.GetStream())
     {
         byte[] buffer = new byte[2048];
         Serializer serializer = new Serializer();
         MessageBroker messageBroker = new MessageBroker();
         messageBroker.Subscribe<RequestMessage>(RequestHandler);
         MessageProcessor processor = new MessageProcessor(messageBroker, serializer);
         StreamHandler handler = new StreamHandler(processor, Guid.NewGuid());
         var read = stream.Read(buffer, 0, 2048);
         while (read > 0)
         {
             handler.ParseStream(buffer, 0, read);
             read = stream.Read(buffer, 0, 2048);
         }
     }
 }
Beispiel #2
0
        private static void TcpClient()
        {
            System.Net.Sockets.TcpClient tcpClient = new TcpClient("127.0.0.1", 9900);

            var stream = tcpClient.GetStream();
            RequestMessage msg = new RequestMessage();
            msg.Integer = 5;
            Serializer serializer = new Serializer();
            var bytes = serializer.Serialize(msg);

            //for (int i = 0; i < 1000; i++)
            while (true)
            {
                stream.Write(bytes, 0, bytes.Length);
                Interlocked.Increment(ref _messageCounter);
            }
        }