C# tcplistener写了一个小例子,但不知道是什么问题导致winform程序无法运行,大神看一下吧...
点击按钮打开ip的监听publicvoidStartListen(){myServerTcp=newTcpListener(IPAddress.Parse(txt_IpA...
点击按钮打开ip的监听
public void StartListen()
{
myServerTcp = new TcpListener(IPAddress.Parse(txt_IpAddress.Text), Convert.ToInt32(txt_Port.Text));
try
{
myServerTcp.Start();
lv_control.Focus();
TcpClient remoteClient = myServerTcp.AcceptTcpClient();
txt_ListenState.Text = "监听已开启...";//如果用winform的话就执行不了这一行,如果用控制台应用就可以执行类似输出的语句
//如:Console.WriteLine("--->客户端" + remoteClient.Client.RemoteEndPoint + "已经联接");
}
catch (Exception ex)
{
txt_ListenState.Text = ex.Message;
}
} 展开
public void StartListen()
{
myServerTcp = new TcpListener(IPAddress.Parse(txt_IpAddress.Text), Convert.ToInt32(txt_Port.Text));
try
{
myServerTcp.Start();
lv_control.Focus();
TcpClient remoteClient = myServerTcp.AcceptTcpClient();
txt_ListenState.Text = "监听已开启...";//如果用winform的话就执行不了这一行,如果用控制台应用就可以执行类似输出的语句
//如:Console.WriteLine("--->客户端" + remoteClient.Client.RemoteEndPoint + "已经联接");
}
catch (Exception ex)
{
txt_ListenState.Text = ex.Message;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询