public WebSocketService() { _workerThread = new Thread(ProcessMessages); _wsServer.OnConnected += context => { Console.WriteLine("Connected: {0}", context.ClientAddress); _users.Add(context); // is this thread safe? }; _wsServer.OnDisconnect += context => Console.WriteLine("Disconnected: {0}", context.ClientAddress); _wsServer.OnReceive += e => { var message = JsonConvert.DeserializeObject <Message>(e.DataFrame.ToString()); StatisticsService.StoreRoundtripTime((int)(TimeService.Now - message.SentTimestamp)); }; _wsServer.Start(); _workerThread.Start(); }
private static void PublishState(int state, WebSocketService service) { service.Publish(new Message { Data = state, SentTimestamp = TimeService.Now, Stats = StatisticsService.GetStats() }); }