我下段代码连接时老是出异常“所请求的地址无效”出现在 socket.Bind(ipEndPoint)。谁能帮我看看啊,急急急急
//打开TCP端口
private void btnConTcp_Click(object sender, EventArgs e)
{
try
{
IPAddress ip=IPAddress.Parse(tbIp.Text);//162.168.200有效的
IPEndPoint ipEndPoint=new IPEndPoint(ip, int.Parse(tbTCPPort.Text));
socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
socket.Blocking = false; //置socket非阻塞状态
socket.Bind(ipEndPoint); //绑定套接字
socket.Connect(ipEndPoint);
if(socket.Connected)
lbMessage.Items.Insert(0,"与主机:" + tbIp.Text + ",端口:" + tbTCPPort.Text + "连接成功");
else
lbMessage.Items.Add("连接失败");
}
catch(Exception ex)
{
lbMessage.Items.Insert(0,"连接失败:"+ex.Message);
}
}
慕的地8271018
三国纷争