Exemplo n.º 1
0
        private void SendCallback(IAsyncResult ar)
        {
            ViewerClient client = (ViewerClient)ar.AsyncState;

            try
            {
                client.sock.EndSend(ar);
            }
            catch (Exception)
            {
                client.disconnected = true;
            }
        }
Exemplo n.º 2
0
        public void Update()
        {
            // Update
            for (int i = 0; i < _clients.Count; i++)
            {
                ViewerClient client = _clients[i];
                if (client.disconnected || client.sock.Connected == false)
                {
                    OnClientDisconnected(client);

                    _clients.RemoveAt(i);
                    if (_clients.Count == 0)
                    {
                        break;
                    }

                    i--;
                }
            }
        }
Exemplo n.º 3
0
        private void AcceptCallback(IAsyncResult ar)
        {
            // Get the socket that handles the client request.
            Socket listener = (Socket)ar.AsyncState;

            try
            {
                ViewerClient client = new ViewerClient();
                client.sock         = listener.EndAccept(ar);
                client.disconnected = false;
                _clients.Add(client);

                OnClientConnected(client);

                // Accept next.
                _listener.BeginAccept(new AsyncCallback(AcceptCallback), _listener);
            }
            catch (Exception ex)
            {
                Log.Out("Unable to accept new client: {0}", ex.Message);
            }
        }
Exemplo n.º 4
0
        private void Send(ViewerClient client, byte[] data, int length)
        {
            var sock = client.sock;

            sock.BeginSend(data, 0, length, 0, new AsyncCallback(SendCallback), client);
        }
Exemplo n.º 5
0
 private void OnClientDisconnected(ViewerClient cl)
 {
     Log.Out("[DebugServer] Client disconnected {0}", cl.sock.RemoteEndPoint);
 }