private void WsServer_OnMessage(string cid, WebSocket.Model.WSProtocal msg)
        {
            if (msg != null)
            {
                if (_dic1.ContainsKey(cid) && msg.Content != null && msg.Content.Any())
                {
                    var name = Encoding.UTF8.GetString(msg.Content);

                    if (string.IsNullOrEmpty(name))
                    {
                        return;
                    }

                    Task.Factory.StartNew(() =>
                    {
                        while (_dic1.ContainsKey(cid))
                        {
                            try
                            {
                                var data = SerializeHelper.Serialize(ServerInfoDataHelper.GetInfo(name));

                                _wsServer.Reply(cid, new WSProtocal(WSProtocalType.Text, Encoding.UTF8.GetBytes(data)));
                            }
                            catch
                            {
                                _dic1.TryRemove(cid, out DateTime v);
                                break;
                            }
                            ThreadHelper.Sleep(1000);
                        }
                    });
                }
                else
                {
                    _wsServer.Disconnect(cid);
                }
            }
        }
Exemple #2
0
        private static void Server_OnMessage(string id, WSProtocal data)
        {
            ConsoleHelper.WriteLine("WSServer 收到{0}的消息:{1}", ConsoleColor.Green, id, Encoding.UTF8.GetString(data.Content));

            _server.Reply(id, data);
        }