Example #1
0
        public static HandshakeMessage ReadFrom(byte[] buffer, int count)
        {
            string value = Encoding.UTF8.GetString(buffer, 0, count);
            var    id    = new HubId(value);

            return(new HandshakeMessage(id));
        }
        private void StartListener()
        {
            var server = new AsyncNetworkStream(_listener.Accept());
            HandshakeMessage handshake = server.ReceiveHandshake().Result;

            server.SendHandshake(HubId.Generate());

            using (var buffer = new PooledMemoryStream())
            {
                while (true)
                {
                    buffer.Reset();
                    Receive(server, buffer, WireHeader.Size);
                    buffer.Position = 0;
                    WireHeader header = WireHeader.ReadFrom(buffer);
                    //Console.WriteLine($"Received {header.MessageHeader} ({header.PayloadSize.Value.ToString(CultureInfo.InvariantCulture)})");
                    Receive(server, buffer, header.PayloadSize.Value);

                    _serverReceived++;

                    if (_serverReceived == _count + 1)
                    {
                        _allMessagesReceived.Set();
                    }
                }
            }
        }
Example #3
0
 public static HandshakeMessage ReadFrom(PooledMemoryStream buffer, int payloadSizeValue)
 {
     using (var reader = new StreamReader(buffer, Encoding.UTF8, false, 16, true))
     {
         string value = reader.ReadToEnd();
         var    id    = new HubId(value);
         return(new HandshakeMessage(id));
     }
 }
Example #4
0
        public void Setup()
        {
            _serializer = new JsonNetSerializer();
            var options = new SolarWindHubOptions(TestContext.LoggerFactory);

            _hub = new SolarWindHub(options);
            _uri = new Uri("tcp://localhost:4312");
            _hub.Listen(new ServerOptions(_uri, _ => new ChannelOptions(_serializer, OnCallback), delegate { }));


            var header = new MessageHeader(new MessageTypeId(1), MessageId.Empty, MessageId.Empty);
            var data   = new TextMessage {
                Text = "Greetings"
            };

            _messageBuffer = new MemoryStream();

            _serializer.SerializeMessage(_messageBuffer, in header, data);

            _clientHubId = new HubId("client");
        }
        internal static async Task <HandshakeMessage> HandshakeAsServer(this AsyncNetworkStream stream, HubId hubId)
        {
            HandshakeMessage incoming = await stream
                                        .ReceiveHandshake()
                                        .ConfigureAwait(false);

            if (incoming == null)
            {
                return(null);
            }

            await stream
            .SendHandshake(hubId)
            .ConfigureAwait(false);

            return(incoming);
        }
        public static async Task <HandshakeMessage> HandshakeAsClient(this AsyncNetworkStream stream, HubId hubId)
        {
            await stream
            .SendHandshake(hubId)
            .ConfigureAwait(false);

            HandshakeMessage handshakeResponse = await stream
                                                 .ReceiveHandshake()
                                                 .ConfigureAwait(false);

            return(handshakeResponse);
        }
Example #7
0
 public HandshakeMessage(HubId hubId)
 {
     HubId = hubId;
 }