首页上一页 1 下一页尾页 1 条记录 1/1页
为什么会说地址无效的?
发表在C#图书答疑
2010-08-10
是否精华
是
否
版块置顶:
是
否
我在练习这个的时候
private void button1_Click(object sender, EventArgs e)
{
TcpListener tcplistener = null;
IPAddress ipaddress = IPAddress.Parse(textBox1.Text);
int port =Convert.ToInt32(textBox2.Text);
tcplistener = new TcpListener(ipaddress, port);
tcplistener.Start();
richTextBox1.Text = "等待连接...\n";
TcpClient tcpclient = null;
if (tcplistener.Pending())
{
tcpclient = tcplistener.AcceptTcpClient();
}
else
{
tcpclient =new TcpClient(textBox1.Text,port);
}
richTextBox1.Text +="连接成功!!";
tcpclient.Close();
tcplistener.Stop();
}
运行结果 地址无效,我输入的地址是局域网的ip.
运行:telnet ip 1433 可行!!
private void button1_Click(object sender, EventArgs e)
{
TcpListener tcplistener = null;
IPAddress ipaddress = IPAddress.Parse(textBox1.Text);
int port =Convert.ToInt32(textBox2.Text);
tcplistener = new TcpListener(ipaddress, port);
tcplistener.Start();
richTextBox1.Text = "等待连接...\n";
TcpClient tcpclient = null;
if (tcplistener.Pending())
{
tcpclient = tcplistener.AcceptTcpClient();
}
else
{
tcpclient =new TcpClient(textBox1.Text,port);
}
richTextBox1.Text +="连接成功!!";
tcpclient.Close();
tcplistener.Stop();
}
运行结果 地址无效,我输入的地址是局域网的ip.
运行:telnet ip 1433 可行!!