c#TcpListener将所有客户端名称和IPAddress的列表发送给每个客户端

时间:2020-04-11 09:51:23

标签: c# list server

如何将客户端名称 ipaddress 的列表发送给所有连接到服务器的客户端 用户服务器

客户以 dwk:192.168.1.88

的格式发送用户名用户地址

        //Global Variables
        List<string> Users = new List<string>();




       client = new TcpClient[100];


            int clientnumber = i;
            String user = "";
           
            client[clientnumber] = (TcpClient)obj;
      
         
          
            networkStream = client[clientnumber].GetStream();





 public void SendUserList()
        {
            byte[] sendBytes = new byte[10025];
          
            string userdlist = "";
              foreach (string u1 in Users)
             {
                  userdlist = userdlist + " " + u1;
              }


// userdlist dwk 192.168.1.88 john 192.168.1.89  etc etc


            MessageBox.Show("Server \n UserList : " + userdlist);
            sendBytes = Encoding.ASCII.GetBytes(userdlist);
             networkStream.Write(sendBytes, 0, sendBytes.Length);
        }

我想要

 networkStream.Write(sendBytes, 0, sendBytes.Length);

向所有客户发送列表

我尝试过

            networkStream = client[1].GetStream();

            string userlist = "";
              foreach (string u1 in Users)
             {
                  userlist = userlist + " " + u1;
              }

            MessageBox.Show("Server \n UserList : " + userlist);
            sendBytes = Encoding.ASCII.GetBytes(userlist);
             networkStream.Write(sendBytes, 0, sendBytes.Length);

没有喜悦... 谢谢

0 个答案:

没有答案