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(); }
public MessageClient(IFramedClient framedClient, IStacksSerializer packetSerializer, IMessageHandler messageHandler) : this(new MessageIdCache(), framedClient, packetSerializer, messageHandler) { }
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(); }
public MessageClientBase(IFramedClient client, IMessageIdCache messageIdCache, IStacksSerializer packetSerializer) { this.framedClient = client; this.messageIdCache = messageIdCache; this.packetSerializer = packetSerializer; }
public MessageClient(IFramedClient framedClient, IStacksSerializer packetSerializer, IMessageHandler messageHandler, Func <MessageIdRegistration, MessageIdRegistration> registration) : this(registration(new MessageIdRegistration()).CreateCache(), framedClient, packetSerializer, messageHandler) { }
public MessageClient(IFramedClient framedClient, IStacksSerializer packetSerializer, IMessageHandler messageHandler, Func<MessageIdRegistration, MessageIdRegistration> registration) : this(registration(new MessageIdRegistration()).CreateCache(), framedClient, packetSerializer, messageHandler) { }
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); }
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")); }
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")); }
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(); }
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); }
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); }
public ActorSession(IFramedClient client) { Client = client; }
public ReactiveMessageClient(IFramedClient framedClient, IStacksSerializer packetSerializer) : this(framedClient, packetSerializer, null) { }