我有一个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
中选择的项目打印消息的问题。有什么建议吗?