Exemple #1
0
            private void Process()
            {
                while (ContinueProcess)
                {
                    ClientHandler client = null;
                    lock (ConnectionPool.SyncRoot)
                    {
                        if (ConnectionPool.Count > 0)
                        {
                            client = ConnectionPool.Dequeue();
                        }
                    }
                    if (client != null)
                    {
                        // if client still connect, schedufor later processingle it
                        if (client.Alive)
                        {
                            client.Process(); // Provoke client
                            ConnectionPool.Enqueue(client);
                        }
                        else
                        {
                            client.Close();
                        }
                    }

                    Thread.Sleep(1);
                }
            }
Exemple #2
0
 public void CancelConnection()
 {
     if (serverHandler != null)
     {
         serverHandler.Close();
         serverHandler = null;
         NetworkServer.Shutdown();
     }
     if (client != null)
     {
         if (clientHandler != null)
         {
             clientHandler.Close();
             clientHandler = null;
         }
         client.Shutdown();
         client = null;
     }
 }
Exemple #3
0
    public void Stop()
    {
        ContinueProcess = false;
        for (int i = 0; i < ThreadTask.Length; i++)
        {
            if (ThreadTask[i] != null && ThreadTask[i].IsAlive)
            {
                ThreadTask[i].Join();
            }
        }

        // Close all client connections
        while (ConnectionPool.Count > 0)
        {
            ClientHandler client = ConnectionPool.Dequeue();
            client.Close();
            Console.WriteLine("Client connection is closed!");
        }
    }
Exemple #4
0
            public void Stop()
            {
                ContinueProcess = false;

                // Close all client connections
                while (ConnectionPool.Count > 0)
                {
                    ClientHandler client = ConnectionPool.Dequeue();
                    client.Close();
                }

                for (int i = 0; i < ThreadTask.Length; i++)
                {
                    if (ThreadTask[i] != null && ThreadTask[i].IsAlive)
                    {
                        ThreadTask[i].Abort();
                    }
                }
            }
        public void Close(bool sendMessage)
        {
            lock (ClientHandler)
            {
                try
                {
                    if (sendMessage)
                    {
                        byte[] messageType = BitConverter.GetBytes((int)Common.SocketMessageTypes.Disconnected);
                        byte[] messageSize = BitConverter.GetBytes(Common.SocketDefaultMessages.Disconnected.Length);

                        var closeMessage = new List <byte>();
                        closeMessage.AddRange(messageType);
                        closeMessage.AddRange(messageSize);
                        closeMessage.AddRange(Common.SocketDefaultMessages.Disconnected);

                        ClientHandler.Send(closeMessage.ToArray());
                    }
                }
                catch (Exception) { }

                try
                {
                    if (ClientHandler.Connected)
                    {
                        ClientHandler.Shutdown(SocketShutdown.Both);
                        ClientHandler.Close();
                    }
                }
                catch (Exception) { }

                if (ConnectionClosed != null)
                {
                    ConnectionClosed.Invoke(this);
                }
            }
        }
Exemple #6
0
 public void Stop()
 {
     ClientHandler?.Close();
 }