public void Subscribe(CensusStreamSubscription subscription)
        {
            var sMessage = JsonConvert.SerializeObject(subscription, sendMessageSettings);

            _logger.LogInformation($"Subscribing to census with: {sMessage}");

            _client.Send(sMessage);
        }
示例#2
0
        private static async Task StartSendingPing(IWebsocketClient client)
        {
            while (true)
            {
                await Task.Delay(1000);

                await client.Send("ping");
            }
        }
示例#3
0
        public bool Send(string data)
        {
            if (!IsConnected)
            {
                _clientLogger.MessageLog("[OUTGOING] Message was not sent, client is not connected.");
                return(false); // if we are not connected, we will just return false
            }

            _client.Send(data);
            return(true);
        }
        public Task SendAsync <T>(IWebsocketClient client, T message, string type = null) where T : IMessage
        {
            var(emitMessage, messageType) = CreateMessage(message, type);
            var payload = JsonConvert.SerializeObject(emitMessage, SerializerSettings);

            if (_logger.IsTrace)
            {
                _logger.Trace($"Sending ETH stats message '{messageType}': {payload}");
            }

            return(client.Send(payload));
        }
示例#5
0
        private static async Task StartSendingPing(IWebsocketClient client)
        {
            while (true)
            {
                await Task.Delay(1000);

                if (!client.IsRunning)
                {
                    continue;
                }

                await client.Send("ping");
            }
        }
示例#6
0
        private async Task HandlePingAsync(string message)
        {
            long   serverTime = long.Parse(message.Split("::").LastOrDefault()?.Replace("\"", string.Empty));
            long   clientTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
            long   latency    = clientTime >= serverTime ? clientTime - serverTime : serverTime - clientTime;
            string pong       = $"\"primus::pong::{serverTime}\"";

            if (_logger.IsDebug)
            {
                _logger.Debug($"Sending 'pong' message to ETH stats...");
            }
            _client.Send(pong);
            await _messageSender.SendAsync(_client, new LatencyMessage(latency));
        }
示例#7
0
        private static async Task StartSendingPing(IWebsocketClient client)
        {
            while (true)
            {
                await Task.Delay(5000);

                if (!client.IsRunning)
                {
                    continue;
                }

                client.Send($"ping{DateTime.Now.Second}");
                Console.WriteLine($"ping{DateTime.Now.Second}");
            }
        }
示例#8
0
        public async Task <string> SendAsync(string message)
        {
            await Task.Delay(1000);

            return(await Task.Run(() =>
            {
                string result = string.Empty;
                webSocketClient.Send(message);
                webSocketClient.MessageReceived.Subscribe(msg =>
                {
                    result = msg.TextData;
                });
                return result;
            }));
        }
示例#9
0
 protected override void MessageReceived(MessageReceived message, IWebsocketClient client)
 {
     try
     {
         if (message != null)
         {
             var result = HandlerMessages?.Invoke(message);
             if (result.HasValue && result.Value)
             {
                 Task.Run(() =>
                 {
                     try
                     {
                         using (var c = new ConfirmMessage(this.keyAccess, this.privateKey))
                         {
                             c.Ok(message.data.Info.Id, message.data.Info.RemoteJid);
                         }
                     }
                     catch (Exception ex)
                     {
                         Console.WriteLine(ex);
                     }
                 });
                 Task.Run(() =>
                 {
                     try
                     {
                         client.Send(JsonConvert.SerializeObject(new
                         {
                             Token = keyAccess,
                             message.data.Info.Id,
                             message.data.Info.RemoteJid
                         }));
                     }
                     catch (Exception ex)
                     {
                         Console.WriteLine(ex);
                     }
                 });
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
示例#10
0
        private async Task StartSendingPing(IWebsocketClient client, CancellationToken cancellation)
        {
            while (true)
            {
                await Task.Delay(10000);

                if (cancellation.IsCancellationRequested)
                {
                    return;
                }

                if (!client.IsRunning)
                {
                    continue;
                }

                client.Send("ping");
            }
        }
        public async Task ConnectAsync(CensusStreamSubscription subscription)
        {
            _client = new WebsocketClient(GetEndpoint(), wsFactory)
            {
                ReconnectTimeout      = TimeSpan.FromSeconds(35),
                ErrorReconnectTimeout = TimeSpan.FromSeconds(30)
            };

            _client.DisconnectionHappened.Subscribe(info =>
            {
                _logger.LogWarning(75421, $"Stream disconnected: {info.Type}: {info.Exception}");

                if (_onDisconnected != null)
                {
                    Task.Run(() => _onDisconnected(info));
                }
            });

            _client.ReconnectionHappened.Subscribe(info =>
            {
                _logger.LogInformation($"Stream reconnection occured: {info.Type}");

                if (subscription.EventNames.Any())
                {
                    var sMessage = JsonConvert.SerializeObject(subscription, sendMessageSettings);

                    _client.Send(sMessage);

                    _logger.LogInformation($"Subscribed to census with: {sMessage}");
                }
            });

            _client.MessageReceived.Subscribe(msg =>
            {
                if (_onMessage != null)
                {
                    Task.Run(() => _onMessage(msg.Text));
                }
            });

            await _client.Start();
        }
示例#12
0
        private void SendResponce(int RoomID, string EUI, string command, int port)
        {
            _context.TriggerLog.Add(new TriggerLog
            {
                RoomID    = RoomID,
                Command   = command,
                Timestamp = DateTime.Now
            });
            _context.SaveChanges();

            var tx = new TXRootObject();

            tx.cmd       = "tx";
            tx.EUI       = EUI;
            tx.confirmed = false;
            tx.port      = port;
            tx.data      = command;

            client.Send(JsonConvert.SerializeObject(tx));
        }
示例#13
0
 private async Task ListenChannelPoints(string channel, string token, bool listen = true)
 {
     try
     {
         if (Client != null && Client.IsRunning)
         {
             string userid = (await Requests.GetUserID(channel)).Item1;
             Client.Send((JObject.FromObject(new
             {
                 type = listen ? "LISTEN" : "UNLISTEN",
                 data = new
                 {
                     topics = new string[] { "channel-points-channel-v1." + userid },
                     auth_token = token
                 }
             })).ToString());
             Debug.WriteLine("Listen Send!");
         }
     }
     catch { }
 }
示例#14
0
        //public bool CompleteStop(isaCommand inputparam)
        //{
        //    //var output = mp.CompleteStop(inputparam);
        //    return true;
        //}


        void SendMsgEventAsync(isaCommand cmd)
        {
            if (oclient == null)
            {
                Logger.Info($"UMDServerConnection:Task SendMsgEventAsync: Client {name} not connected");
                if (!bStopped)
                {
                    bRunning = false;
                    //StartAsync();
                    Thread.Sleep(100);
                }
            }
            Logger.Info($"UMDServerConnection SendMsgEventAsync {name} {cmd.ToString()}");
            Task retTsk = oclient.Send(cmd.ToArray());

            if (timer != null)
            {
                timer.Change(200, 10000);
            }
            if (retTsk.Status == TaskStatus.Faulted)
            {
                Logger.Info($"UMDServerConnection:Task SendMsgEventAsync: faulted {name}  " + cmd.ToString());
            }
        }
示例#15
0
 private void Send(Packet packet)
 {
     ThrowIfNotRunning();
     _socket.Send(PacketParser.Encode(packet));
 }
示例#16
0
 static void Send(IMessage message, IWebsocketClient ws)
 {
     using var ms = new MemoryStream();
     message.WriteDelimitedTo(ms);
     ws.Send(ms.GetBuffer());
 }