示例#1
0
        static void Main(string[] args)
        {
            encoding = Encoding.ASCII;
            SocketServer server;

            server = new SocketServer(new IPEndPoint(IPAddress.Loopback, 0));

            server.Connected.Subscribe(c =>
            {
                serverClient = new FramedClient(c);

                // When received is called, bs will contain no more and no less
                // data than whole packet as sent from client.
                serverClient.Received.Subscribe(bs =>
                {
                    var msg = encoding.GetString(bs.Array, bs.Offset, bs.Count);
                    msg     = "Hello, " + msg + "!";
                    serverClient.SendPacket(encoding.GetBytes(msg));
                });
            });

            server.Start();
            HandleClient(server.BindEndPoint.Port);

            Console.WriteLine("Press any key to stop...");
            Console.ReadKey();

            server.Stop();
            client.Close();
            serverClient.Close();
        }
示例#2
0
 public MessageClient(IFramedClient framedClient,
                      IStacksSerializer packetSerializer,
                      IMessageHandler messageHandler)
     : this(new MessageIdCache(),
            framedClient, packetSerializer, messageHandler)
 {
 }
示例#3
0
文件: Program.cs 项目: Rush/Stacks
        static void Main(string[] args)
        {
            encoding = Encoding.ASCII;
            SocketServer server;
            server = new SocketServer(new IPEndPoint(IPAddress.Loopback, 0));

            server.Connected += c =>
                {
                    serverClient = new FramedClient(c);

                    // When received is called, bs will contain no more and no less
                    // data than whole packet as sent from client.
                    serverClient.Received += bs =>
                        {
                            var msg = encoding.GetString(bs.Array, bs.Offset, bs.Count);
                            msg = "Hello, " + msg + "!";
                            serverClient.SendPacket(encoding.GetBytes(msg));
                        };
                };

            server.Start();
            HandleClient(server.BindEndPoint.Port);
            
            Console.WriteLine("Press any key to stop...");
            Console.ReadKey();

            server.Stop();
            client.Close();
            serverClient.Close();
        }
示例#4
0
 public MessageClientBase(IFramedClient client, IMessageIdCache messageIdCache,
                          IStacksSerializer packetSerializer)
 {
     this.framedClient     = client;
     this.messageIdCache   = messageIdCache;
     this.packetSerializer = packetSerializer;
 }
示例#5
0
 public MessageClient(IFramedClient framedClient, 
                      IStacksSerializer packetSerializer,
                      IMessageHandler messageHandler)
     : this(new MessageIdCache(),
            framedClient, packetSerializer, messageHandler)
 {
 }
示例#6
0
 public MessageClient(IFramedClient framedClient,
                      IStacksSerializer packetSerializer,
                      IMessageHandler messageHandler,
                      Func <MessageIdRegistration, MessageIdRegistration> registration)
     : this(registration(new MessageIdRegistration()).CreateCache(),
            framedClient, packetSerializer, messageHandler)
 {
 }
示例#7
0
 public MessageClient(IFramedClient framedClient,
                      IStacksSerializer packetSerializer,
                      IMessageHandler messageHandler,
                      Func<MessageIdRegistration, MessageIdRegistration> registration)
     : this(registration(new MessageIdRegistration()).CreateCache(), 
            framedClient, packetSerializer, messageHandler)
 {
 }
示例#8
0
        private MessageClient(IMessageIdCache messageIdCache, 
                              IFramedClient framedClient,
                              IStacksSerializer packetSerializer,
                              IMessageHandler messageHandler)
            : base(framedClient, messageIdCache, packetSerializer)
        {
            this.packetSerializationHandler = new StacksSerializationHandler(
                                            messageIdCache,
                                            this,
                                            packetSerializer,
                                            messageHandler);

            this.framedClient.Received.Subscribe(PacketReceived);
        }
示例#9
0
文件: Program.cs 项目: Rush/Stacks
        static async void HandleClient(int serverPort)
        {
            client = new FramedClient(
                            new SocketClient());

            client.Received += bs =>
                {
                    Console.WriteLine("Received: " +
                        encoding.GetString(bs.Array, bs.Offset, bs.Count));
                };
            
            await client.Connect(new IPEndPoint(IPAddress.Loopback, serverPort));
            client.SendPacket(encoding.GetBytes("Steve"));
        }
示例#10
0
        private MessageClient(IMessageIdCache messageIdCache,
                              IFramedClient framedClient,
                              IStacksSerializer packetSerializer,
                              IMessageHandler messageHandler)
            : base(framedClient, messageIdCache, packetSerializer)
        {
            this.packetSerializationHandler = new StacksSerializationHandler(
                messageIdCache,
                this,
                packetSerializer,
                messageHandler);

            this.framedClient.Received.Subscribe(PacketReceived);
        }
示例#11
0
        static async void HandleClient(int serverPort)
        {
            client = new FramedClient(
                new SocketClient());

            client.Received.Subscribe(bs =>
            {
                Console.WriteLine("Received: " +
                                  encoding.GetString(bs.Array, bs.Offset, bs.Count));
            });

            await client.Connect(new IPEndPoint(IPAddress.Loopback, serverPort));

            client.SendPacket(encoding.GetBytes("Steve"));
        }
示例#12
0
文件: Program.cs 项目: wushian/Stacks
        static void Main(string[] args)
        {
            ServerHelpers.CreateServerAndConnectedClient(out s, out c1, out c2);

            c1.Disconnected.Subscribe(exn => { Console.WriteLine("C1 d/c " + exn); });
            c2.Disconnected.Subscribe(exn => { Console.WriteLine("C2 d/c " + exn); });

            fc1 = new FramedClient(c1);
            fc2 = new FramedClient(c2);

            Measure(8192, 8192);
            Console.ReadLine();
            Measure(8192, 8192 * 16);

            Console.ReadLine();
        }
示例#13
0
        static void Main(string[] args)
        {
            ServerHelpers.CreateServerAndConnectedClient(out s, out c1, out c2);

            c1.Disconnected.Subscribe(exn => { Console.WriteLine("C1 d/c " + exn); });
            c2.Disconnected.Subscribe(exn => { Console.WriteLine("C2 d/c " + exn); });

            fc1 = new FramedClient(c1);
            fc2 = new FramedClient(c2);

            Measure(8192, 8192);
            Console.ReadLine();
            Measure(8192, 8192 * 16);

            Console.ReadLine();
        }
示例#14
0
        public ActorRemoteMessageClient(IFramedClient client)
        {
            framedClient     = client;
            packetSerializer = new ProtoBufStacksSerializer();

            framedClient.Received.Subscribe(PacketReceived);
            framedClient.Connected.Subscribe(OnConnected);
            framedClient.Disconnected.Subscribe(OnDisconnected);

            handshakeCompleted  = new AsyncSubject <Unit>();
            disconnectedSubject = new AsyncSubject <Exception>();

            protocolHandlers = new Dictionary <int, Action <IntPtr, MemoryStream> >();
            protocolHandlers[Proto.ActorProtocol.HandshakeId] = HandleHandshakeMessage;
            protocolHandlers[Proto.ActorProtocol.PingId]      = HandlePingMessage;

            pingTimer = new Timer(OnPingTimer, null, Timeout.Infinite, Timeout.Infinite);
        }
示例#15
0
        public ReactiveMessageClient(IFramedClient framedClient,
                                     IStacksSerializer packetSerializer,
                                     Action <ReactiveClientModelBuilder <T> > modelBuilder)
            : base(framedClient, new MessageIdCache(), packetSerializer)
        {
            Ensure.IsNotNull(framedClient, "framedClient");
            Ensure.IsNotNull(packetSerializer, "packetSerializer");

            var mb = new ReactiveClientModelBuilder <T>();

            if (modelBuilder != null)
            {
                modelBuilder(mb);
            }

            this.messageReceiverCreator = new ReactiveMessageReceiverCreator <T>(base.messageIdCache, packetSerializer, mb);

            this.Packets = this.messageReceiverCreator.CreateReceiverImplementation(out deserializeByMessageId);

            this.framedClient.Received.Subscribe(PacketReceived);
        }
示例#16
0
 public ActorSession(IFramedClient client)
 {
     Client = client;
 }
示例#17
0
 public ActorSession(IFramedClient client)
 {
     Client = client;
 }
示例#18
0
 public ReactiveMessageClient(IFramedClient framedClient,
                              IStacksSerializer packetSerializer)
     : this(framedClient, packetSerializer, null)
 {
 }