Socket + Отключение клиента
От: EyfelFenk Россия  
Дата: 21.03.10 01:01
Оценка:
Я только учусь не ругайте сильно.

Есть вот такой код:
      IPAddress ipAddress = Dns.GetHostAddresses("127.0.0.1")[0];
      TcpListener serverListener = new TcpListener(ipAddress, 8888);
      serverListener.Start();
      serverListener.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), serverListener);


        private static LinkedList<TcpClient> clientList = new LinkedList<TcpClient>();

    // Process the client connection.
    public static void DoAcceptTcpClientCallback(IAsyncResult ar) {
      // Get the listener that handles the client request.
      TcpListener listener = (TcpListener) ar.AsyncState;

      // End the operation and display the received data on  the console.
      TcpClient client = listener.EndAcceptTcpClient(ar);
      clientList.AddLast(client);

      // Process the connection here. (Add the client to a server table, read data, etc.)
      NetworkStream clientStream = client.GetStream();

      Console.WriteLine("Client connected completed. Total clients:" + clientList.Count);

      // Signal the calling thread to continue.
      //tcpClientConnected.Set();
    }


Вся проблема в том, что DoAcceptTcpClientCallback срабатывает только один раз =( А как перехватить момент подключение к серверу и момент отключения от сервера?

Спасибо.
... << RSDN@Home 1.2.0 alpha 4 rev. 1446>>
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.