Пример #1
0
        async Task HandleClientAsync(Client newClient)
        {
            _clients.Add(newClient);



            newClient.ClientId = ++_currentClientId;

            //var sendThread = new Thread(newClient.StartSend);
            //sendThread.Start();


            await newClient.StartSendAsync();

            newClient.SendMessage(new Message
            {
                ClientId    = 0,
                MessageText = $"ACTION={ServerActions.ClientId};CLIENTID={newClient.ClientId}",
            });

            foreach (var client in _clients)
            {
                if (client == newClient)
                {
                    continue;
                }

                newClient.SendMessage(new Message
                {
                    ClientId    = 0,
                    MessageText = $"ACTION={ServerActions.NewClientConnected};NEWCLIENTID={client.ClientId};NICKNAME={client.Nickname}",
                });
            }


            newClient.MessageReceived += OnMessageReceived;

            //var receiveThread = new Thread(newClient.StartReceive);
            //receiveThread.Start();


            await newClient.StartReceiveAsync();
        }
Пример #2
0
        async Task HandleClientAsync(Client newClient)
        {
            

            _clients.Add(newClient);



            newClient.ClientId = ++_currentClientId;

            //var sendThread = new Thread(newClient.StartSend);
            //sendThread.Start();


            await newClient.StartSendAsync();

            newClient.SendMessage(new Message
            {
                ClientId = 0,
                MessageText = $"ACTION={ServerActions.ClientId};CLIENTID={newClient.ClientId}",
            });

            foreach (var client in _clients)
            {
                if (client == newClient)
                    continue;

                newClient.SendMessage(new Message
                {
                    ClientId = 0,
                    MessageText =$"ACTION={ServerActions.NewClientConnected};NEWCLIENTID={client.ClientId};NICKNAME={client.Nickname}",
                });

            }


            newClient.MessageReceived += OnMessageReceived;

            //var receiveThread = new Thread(newClient.StartReceive);
            //receiveThread.Start();


            await newClient.StartReceiveAsync();
          
          
           
        }