Ejemplo n.º 1
0
        private void OnClose(IWebSocketConnection socket)
        {
            var un = socket.GetPaarmiter(username);

            userlist.Remove(un);
            CreateMsg.Run(updatelist());
        }
Ejemplo n.º 2
0
        private void Open(IWebSocketConnection socket)
        {
            var v = socket.GetPaarmiter(username);

            //如果未取到用户名,则断开连接
            if (string.IsNullOrWhiteSpace(v))
            {
                socket.Close();
                return;
            }
            if (!userlist.ContainsKey(v))
            {
                userlist.Add(v, socket);
                CreateMsg.Run(updatelist());
            }
            else
            {
                var n = CreateMsg.CreateMsgRequest("在其他地方登入");
                n.RecUserlist.Add(v);
                CreateMsg.Run(n);
                userlist[v].Close();
                userlist.Add(v, socket);
                CreateMsg.Run(updatelist());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// websocket注册
        /// </summary>
        public void WebsocketRegedit()
        {
            UseSocket use = UseSocket.CreateSocket();

            use.Message = (username, Message) =>
            {
                var result = JsonConvert.DeserializeObject <Request>(Message);
                if (result.ClientType.type == "File")
                {
                    var item = CreateMsg.Run(result);
                    use.CreatStream(username, (UpFileInfo)item.Content);
                }
                else
                {
                    CreateMsg.Run(result);
                }
            };
            use.BinaryMessage = (username, key) =>
            {
                use.listfs[username].Write(key);
            };
        }