コード例 #1
0
        public void AcceptCallback(IAsyncResult ar)
        {
            // Signal the main thread to continue.
            allDone.Set();

            // Get the socket that handles the client request.
            Socket listener = (Socket)ar.AsyncState;
            Socket handler = listener.EndAccept(ar);
            ClientConnection connection = new ClientConnection();
            connection.socket = handler;
            connection.setInfoFromSocket();

            System.Windows.Application.Current.Dispatcher.Invoke(new Action(() => {
                clientsToConnect.Add(connection.stringId, connection);
                txbNewConnections.Text = "" + clientsToConnect.Count;
            }));

            connection.Receive();
        }
コード例 #2
0
 private void disconnectClient(ClientConnection client, bool notifyOthers = false)
 {
     removeClient(client.stringId);
     if (notifyOthers)
     {
         sendMessageToAll(new MessageLIS('D', client.stringId));
     }
 }
コード例 #3
0
        private void addNewClientConnection(string host, int port, bool onlyConnect = false)
        {
            ClientConnection client = new ClientConnection();
            client.stringId = client.host + ":" + client.port;
            //this.client = client;
            client.id = 1;
            client.host = host;
            client.port = port;
            client.onlyConnect = onlyConnect;

            client.startConnecting();
            addClient(client);
        }
コード例 #4
0
 private void addClient(ClientConnection client)
 {
     if(clients.ContainsKey(client.stringId))
     {
         clients.Remove(client.stringId);
     }
     clients.Add(client.stringId, client);
     updateGUICounters();
 }
コード例 #5
0
 internal void handleClientException(ClientConnection client, Exception ex)
 {
     System.Windows.Application.Current.Dispatcher.Invoke(new Action(() => {
         if (ex is SocketException || ex is ObjectDisposedException)
         {
             disconnectClient(client, true);
             checkActions();
         }
     }));
 }