Ejemplo n.º 1
0
        public async Task send_and_receive()
        {
            var timeout = new CancellationTokenSource();

            timeout.CancelAfter(60.Seconds());

            JsonSerialization.RegisterType("socket-pong", typeof(SocketPong));

            using (var client = new ClientWebSocket())
            {
                await client.ConnectAsync("ws://127.0.0.1:3010".ToUri(), timeout.Token);

                var outgoing = new SocketPing {
                    Name = "Kareem Hunt"
                }.ToCleanJson();
                await client.SendMessageAsync(outgoing);

                var buffer = new ArraySegment <byte>(new byte[1000]);

                var result = await client.ReceiveAsync(buffer, timeout.Token);

                var json = buffer.ReadString(result);
                JsonSerialization.DeserializeMessage(json)
                .ShouldBeOfType <SocketPong>()
                .Name.ShouldBe("Kareem Hunt");
            }
        }
Ejemplo n.º 2
0
 public SocketPong Handle(SocketPing ping)
 {
     return(new SocketPong {
         Name = ping.Name
     });
 }