【发布时间】:2013-12-03 06:31:41
【问题描述】:
我正在学习套接字编程,每当我启动我的服务器时,它就会被冻结。
这是我的代码:
IPAddress ipAdd = IPAddress.Parse(textBox1.Text);
TcpListener tcpListen = new TcpListener(ipAdd, Convert.ToInt32( textBox2.Text));
tcpListen.Start();
Socket s = tcpListen.AcceptSocket();
//Get the data
byte[] b = new byte[100];
int k = s.Receive(b);
richTextBox1.AppendText(k.ToString());
listiplbl.Text = textBox1.Text;
listportlbl.Text = textBox2.Text;
srvrstatuslbl.Text = "Running";
actconslbl.Text = "1";
另外,我不太确定是否可以使用此代码连接多个客户端。我的程序很简单。我计划在每台 PC 上安装一个客户端,它应该向我发送计算机的名称和它的 ip。如果我通过我的服务器查询一个 IP,客户端也应该回复相同的详细信息。请使用简单的术语或解释。这是我第一次使用套接字,我正在努力理解。
【问题讨论】:
-
This 应该能帮到你