Beispiel #1
0
        private static void SendClosedMessage()
        {
            string[] clients = _clients.Values.ToArray();

            Array.ForEach(clients, (client) =>
            {
                CallbackResult msg = new CallbackResult()
                {
                    Tag = "closed", Payload = new { id = Guid.Parse(client).ToString() }
                };
                _websocketService.Send(client, msg, (isOK) =>
                {
                    if (!isOK)
                    {
                        RemoveClient(client);
                    }
                });
            });
        }
Beispiel #2
0
 public void Send(string clientID, CallbackResult res, Action<bool> callback= null)
 {
     string id = clientID.Replace("-", "");
     WebSocketServiceHost host;
     if (this._socketServer.WebSocketServices.TryGetServiceHost(this._path, out host))
     {
         IWebSocketSession session;
         if (host.Sessions.TryGetSession(id, out session))
         {
             if (callback == null)
                 callback = (isOK) => { };
             string data = Newtonsoft.Json.JsonConvert.SerializeObject(res);
             session.Context.WebSocket.SendAsync(data, callback);
         }
         else
         {
             if (callback != null)
                 callback(false);
         }
     }
 }
 private void _Send(CallbackResult res)
 {
     base.SendAsync(Newtonsoft.Json.JsonConvert.SerializeObject(res), (isOk) => { });
 }
Beispiel #4
0
        private static void SendClosedMessage()
        {
            string[] clients = _clients.Values.ToArray();

            Array.ForEach(clients, (client) =>
            {
                CallbackResult msg = new CallbackResult() { Tag = "closed", Payload = new {id = Guid.Parse(client).ToString() } };
                _websocketService.Send(client, msg, (isOK) =>
                {
                    if (!isOK)
                        RemoveClient(client);
                });
            });
        }
Beispiel #5
0
 private static async Task TryGetAndPostMessages(CancellationToken ct)
 {
     //Demo Test: Generating Random messages at random intervals and send it to all clients
     Random rnd = new Random();
     await Task.Delay(rnd.Next(400, 2000), ct);
     if (ct.IsCancellationRequested)
         return;
     string[] clients = _clients.Values.ToArray();
     Array.ForEach(clients, (client) =>
     {
         CallbackResult msg = new CallbackResult() { Tag = "message", Payload = new { message = getQuote() } };
         _websocketService.Send(client, msg, (isOK) =>
         {
             if (!isOK)
                 RemoveClient(client);
         });
     });
 }
Beispiel #6
0
 private void _Send(CallbackResult res)
 {
     base.SendAsync(Newtonsoft.Json.JsonConvert.SerializeObject(res), (isOk) => { });
 }