0

我有一个comboBox1连接到服务器的客户端列表。目前在我的代码中,我正在打印从客户端收到的消息到服务器textBox1。但现在我只想为textBox1我在 中选择的客户端打印消息comboBox1

以下是我的代码。

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    string selected = (string)comboBox1.SelectedItem;

    if(selected == "Client:ip address") {
        // I want to print messages for the client selected in comboBox1
    }
}

public void server()
{
    Socket socketForClient;
    socketForClient = tcpListener.AcceptSocket();

    if (socketForClient.Connected)
    {
        NetworkStream networkStream = new NetworkStream(socketForClient);
        System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(networkStream);
        System.IO.StreamReader streamReader = new System.IO.StreamReader(networkStream);
        string theString = "";
        //hello = socketForClient.RemoteEndPoint.ToString();
        while (true)
        {
            theString = streamReader.ReadLine();

            // textBox2.Text = textBox2.Text + "\r\n" + string.Format("Message recieved from client(" + socketForClient.RemoteEndPoint + ") : " + theString);
            display(theString, socketForClient); 
        }

那么如何更改我的代码来解决仅打印comboBox1. 有什么建议吗?

4

0 回答 0