示例#1
0
///---------------------------------------------------------------------------------
/// Client
///---------------------------------------------------------------------------------

        public void closeClient(IWebSocketConnection clientSock)
        {
            if (!clientSock.IsAvailable)
            {
                return;
            }
            Socket serverSock = null;

            if (myGlobals.ClientServer.ContainsKey(clientSock))
            {
                serverSock = myGlobals.ClientServer[clientSock];
            }
            if (wsServer.allSockets.Contains(clientSock))
            {
                // toClient.Close(clientSock);
                wsServer.closeConnection(clientSock);
            }
            wsServer.allSockets.Remove(clientSock);
            if (myGlobals.ClientServer.ContainsKey(clientSock))
            {
                myGlobals.ClientServer.Remove(clientSock);
            }
            //if (myGlobals.ServerClient.ContainsValue(serverSock))

            if (serverSock != null)
            {
                if (myGlobals.ServerClient.ContainsKey(serverSock))
                {
                    myGlobals.ServerClient.Remove(serverSock);
                }
            }
            string operatorName = myGlobals.operatorData.getOperatorName(clientSock);

            if (operatorName != null)
            {
                if (myGlobals.operatorData.operators.ContainsKey(operatorName))
                {
                    myGlobals.operatorData.operators.Remove(operatorName);
                }
            }
            if (clientTimers.ContainsKey(clientSock))
            {
                clientTimers[clientSock].stop();
                clientTimers.Remove(clientSock);
            }

            long sock = clientSock.GetHashCode();

            PublishMessage(logBox1, string.Format("Client {0}(socket:{1}) has been disconnected!", clientSock.ConnectionInfo, sock));
        }
示例#2
0
 static void OnConnected(IWebSocketConnection socket)
 {
     Console.WriteLine($"> {socket.GetHashCode()}");
 }
示例#3
0
 private static void OnDisconnect(IWebSocketConnection socket)
 {
     Console.WriteLine($"< {socket.GetHashCode()}");
 }
示例#4
0
///---------------------------------------------------------------------------------
/// Client
///---------------------------------------------------------------------------------

        public void closeClient(IWebSocketConnection clientSock)
        {
            if (!clientSock.IsAvailable)
                return;
           Socket serverSock = null;
           if (myGlobals.ClientServer.ContainsKey(clientSock))
               serverSock = myGlobals.ClientServer[clientSock];
            if (wsServer.allSockets.Contains(clientSock))
                // toClient.Close(clientSock);
                wsServer.closeConnection(clientSock);
                wsServer.allSockets.Remove(clientSock);
            if (myGlobals.ClientServer.ContainsKey(clientSock))
                myGlobals.ClientServer.Remove(clientSock);
            //if (myGlobals.ServerClient.ContainsValue(serverSock))

            if (serverSock != null)
            {
                if (myGlobals.ServerClient.ContainsKey(serverSock))
                    myGlobals.ServerClient.Remove(serverSock);
            }
            string operatorName = myGlobals.operatorData.getOperatorName(clientSock);

            if (operatorName != null)
            {
                if (myGlobals.operatorData.operators.ContainsKey(operatorName))
                    myGlobals.operatorData.operators.Remove(operatorName);
            }
            if (clientTimers.ContainsKey(clientSock))
            {
                clientTimers[clientSock].stop();
                clientTimers.Remove(clientSock);
            }

            long sock = clientSock.GetHashCode();
            PublishMessage(logBox1, string.Format("Client {0}(socket:{1}) has been disconnected!", clientSock.ConnectionInfo, sock));
        }