Ejemplo n.º 1
0
        public IDisposable StartServerWithAck(Action <byte[]> assert)
        {
            var listener = SocketEvents.CreateTcpStreamListener(5050);

            return(listener
                   .Subscribe(connection =>
            {
                var contexts = connection
                               .ToLengthPrefixed()
                               .Subscribe(m =>
                {
                    Console.WriteLine("Server Received {0} bytes", m.Message.Length);
                    if (assert != null)
                    {
                        assert(m.Message);
                    }
                    var next = Interlocked.Increment(ref _sequence);
                    var sequence = BitConverter.GetBytes(next);
                    Contract.Assert(sequence.Length == 4);
                    m.Publish(sequence);
                },
                                          ex => Console.WriteLine(ex.Message),
                                          () => Console.WriteLine("Disconnected"));
            }));
        }
Ejemplo n.º 2
0
        public static IDisposable StartServer()
        {
            var listener = SocketEvents.CreateTcpStreamListener(5050);

            return(listener
                   .Subscribe(connection =>
            {
                var messages = connection.ToLengthPrefixed();
                messages.Subscribe(m =>
                {
                    Console.WriteLine("Received {0} bytes", m.Message.Length);
                    m.Publish(m.Message);
                },

                                   ex => Console.WriteLine(ex.Message),
                                   () => Console.WriteLine("Disconnected"));
            }));
        }
Ejemplo n.º 3
0
        public IDisposable StartServer(Action <byte[]> assert)
        {
            var listener = SocketEvents.CreateTcpStreamListener(5050);

            return(listener
                   .Subscribe(connection =>
            {
                var contexts = connection
                               .ToLengthPrefixed()
                               .Subscribe(m =>
                {
                    Console.WriteLine("Received {0} bytes", m.Message.Length);
                    if (assert != null)
                    {
                        assert(m.Message);
                    }
                },
                                          ex => Console.WriteLine(ex.Message),
                                          () => Console.WriteLine("Disconnected"));
            }));
        }
Ejemplo n.º 4
0
        public static IDisposable StartServer()
        {
            var listener = SocketEvents.CreateTcpStreamListener(5050);

            return(listener
                   .Subscribe(connection =>
            {
                var messages = connection.ToLengthPrefixed();
                messages.Subscribe(m =>
                {
                    if (m.Message.Length < 1024)
                    {
                        Console.WriteLine("Received {0} bytes: {1}", m.Message.Length, Encoding.ASCII.GetString(m.Message));
                    }
                    else
                    {
                        Console.WriteLine("Received {0} bytes", m.Message.Length);
                    }
                },
                                   ex => Console.WriteLine(ex.Message),
                                   () => Console.WriteLine("Disconnected"));
            }));
        }