socket.bind(myserver) 错误提示提供了无效参数????在线结贴
if (myServer == null)
{
myServer = new IPEndPoint(IP, Port);
socketlistener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
while (!isConnected)
{
try
{
socketlistener.Bind(myServer);
socketlistener.Listen(0);
isConnected = true;
thread = new Thread(new ThreadStart(target));//监听命令
thread.Start();
textBox1.AppendText("侦听已开始!");
}
为什么IP跟端口一样,第二次Bind时会出现提供参数无效异常???
------解决方案--------------------
if (myServer == null)
{
myServer = new IPEndPoint(IP, Port);
socketlistener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socketlistener.Bind(myServer);
socketlistener.Listen(0);
}
while (!isConnected)
{
try
{
isConnected = true;
thread = new Thread(new ThreadStart(target));//监听命令
thread.Start();
textBox1.AppendText("侦听已开始!");
}
------解决方案--------------------代码没有问题啊,你是不是 Bind 了两次