C#网络编程的问题,救命啊,这是怎么回事啊
好吧直接上代码,这是MSDN上套接字使用的服务器端代码,我在窗体上用了个按钮和个Textbox,然后我逐行调试,每次到按下按钮后窗体就现实没有响应了!什么原理啊各位大神!
namespace socket_text
{
public partial class Server : Form
{
static string output = "";
public Server()
{
InitializeComponent();
}
public void createListener()
{
// Create an instance of the TcpListener class.
TcpListener tcpListener = null;
IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
try
{
// Set the listener on the local IP address
// and specify the port.
tcpListener = new TcpListener(ipAddress, 13);
tcpListener.Start();
output = "Waiting for a connection...";
}
catch (Exception e)
{
output = "Error: " + e.ToString();
MessageBox.Show(output);
}
while (true)
{
// Always use a Sleep call in a while(true) loop