Example #1
0
        private void AcceptSocketCallback(IAsyncResult result)
        {
            var socket = _listener.EndAcceptSocket(result);
            var client = new TCPSocket(socket);

            lock (_clients)
                _clients.Add(client);

            socket.BeginReceive(client.Buffer, 0, client.Buffer.Length, 0, ReadCallback, client);
            _listener.BeginAcceptTcpClient(AcceptSocketCallback, null);
        }
Example #2
0
 public void Send(TCPSocket tcpSocket, byte[] bytes)
 {
     try
     {
         tcpSocket.Socket.BeginSend(bytes, 0, bytes.Length, 0, SendCallback, tcpSocket);
     }
     catch (Exception)
     {
         lock (_clients)
         {
             _clients.RemoveAll(x => x.Socket == tcpSocket.Socket);
         }
     }
 }