Esempio n. 1
0
 public void AddClient(ChatClient client)
 {
     NewClientConnectedEvent?.Invoke(client.Username);
     SendMessageEvent        += client.ReceiveMessage;
     NewClientConnectedEvent += client.ClientConnectedMessage;
     ClientDisconnectedEvent += client.ClientDisconnectedMessage;
 }
Esempio n. 2
0
        private void AcceptCallback(IAsyncResult ar)
        {
            listenerSocket.BeginAccept(new AsyncCallback(AcceptCallback), listenerSocket);
            connectionEstablished.Set();
            Socket listener = (Socket)ar.AsyncState;
            Socket handler  = listener.EndAccept(ar);

            C.log.Info("Connection established with a client " + handler.RemoteEndPoint.ToString());
            NewClientConnectedEvent?.Invoke(handler);
            while (IsListening)
            {
                try {
                    asynchronousCommunicationUtils.ListenForMessages(handler);
                } catch (SocketException) {
                    C.log.Info("Connection lost towards " + handler.RemoteEndPoint.ToString());
                    return;
                }
            }
        }