Example #1
0
        public void Publish(IMessage message)
        {
            Packet packet = new Packet();

            packet.SenderId = _mhs.ServiceId;
            packet.Message  = message;

            string data = JsonConvert.SerializeObject(packet);

            _stream.Send(data);
        }
Example #2
0
        public void Connect()
        {
            _client.Connect(_ipAddress, _port);
            _stream = new TcpStream(_client.GetStream());

            _mhs.MessageSubscriptions = _subscriptions;
            string data = JsonConvert.SerializeObject(_mhs);

            _stream.Send(data);

            Thread receiveThread = new Thread(new ThreadStart(ReceiveMessages));

            receiveThread.Start();
        }
Example #3
0
        private UniTask ProcessOutgoingMessages()
        {
            while (!_cancellationToken.IsCancellationRequested)
            {
                for (int messageIndex = 0; messageIndex < _queueOutgoingData.Count; messageIndex++)
                {
                    if (_queueOutgoingData.TryDequeue(out Message outgoing))
                    {
                        _client?.Send(new ArraySegment <byte>(outgoing.Data));
                    }

                    UniTask.Delay(1);
                }

                UniTask.Delay(1);
            }

            Libuv2kNGLogger.Log("Shutting down processing task");

            return(UniTask.CompletedTask);
        }
Example #4
0
        public void RouteMessage(object message)
        {
            string messageType = ((dynamic)message).MessageType;

            List <MessageHandshakeSocket> registeredClients = _clients.Where(s => s.Value.MessageSubscriptions.Contains(messageType))
                                                              .Select(s => s.Value)
                                                              .ToList();

            foreach (MessageHandshakeSocket client in registeredClients)
            {
                TcpStream stream      = new TcpStream(client.Client.GetStream());
                string    sendMessage = JsonConvert.SerializeObject(message);

                try
                {
                    stream.Send(sendMessage);
                }
                catch //Client has disconnected
                {
                    DisconnectClient(client);
                }
            }
        }
Example #5
0
 public override void ClientSend(int channelId, ArraySegment <byte> segment)
 {
     client?.Send(segment);
 }