Exemple #1
0
 public ChatServer(IPAddress address, int port, string name = DefaultServerName)
 {
     Address         = address;
     Port            = port;
     Name            = name;
     _clients        = new List <ClientHandler>();
     _broadcastQueue = new BroadcastBlockingQueue <Message>();
 }
Exemple #2
0
        public ClientHandler(Socket socket, BroadcastBlockingQueue <Message> broadcastQueue)
        {
            _socket         = socket;
            _broadcastQueue = broadcastQueue;

            Name = $"Anonymous{Random.Next(10000, 99999)}";

            _messageQueue = new BlockingQueue <Message>();
            _broadcastQueue.Register(_messageQueue);

            _sendThread = new Thread(SendProc)
            {
                IsBackground = true
            };
            _sendThread.Start();

            _receiveThread = new Thread(ReceiveProc)
            {
                IsBackground = true
            };
            _receiveThread.Start();
        }