tcplistener does not start

本文关键字:start not does tcplistener | 更新日期: 2023-09-27 18:11:34

我在Windows窗体应用程序中使用TcpListener;它有一个启动TcpListener的"开始"按钮。但是,当我单击开始按钮时,会抛出以下异常:

请求的地址在其上下文中无效

这是我用来启动侦听器的代码:

IPAddress FriendIp = IPAddress.Parse(IpAddress);
server = new TcpListener(FriendIp, PortNum);
server.Start();

这是异常的调用堆栈:

System.dll!System.Net.Sockets.Socket.DoBind(System.Net.EndPoint endPointSnapshot, System.Net.SocketAddress socketAddress) + 0x9f bytes  
System.dll!System.Net.Sockets.Socket.Bind(System.Net.EndPoint localEP) + 0xd2 bytes 
System.dll!System.Net.Sockets.TcpListener.Start(int backlog) + 0x91 bytes   
System.dll!System.Net.Sockets.TcpListener.Start() + 0xa bytes   

BlueBall.exe ! BlueBall.Chat_Window。Chat_Window(string ipadd, int port, bool serverclientjob)第46行+ 0x10字节c#BlueBall.exe ! BlueBall.BlueBall。Main_ListBox_DoubleClick(对象发送者,系统。e)第221行+ 0x29字节c#System.Windows.Forms.dll ! System.Windows.Forms.Control.OnDoubleClick(系统。EventArgs e) + 0x7f bytes
System.Windows.Forms.dll ! System.Windows.Forms.ListBox。WndProc(ref System.Windows.Forms.Message m) + 0x2c9字节System.Windows.Forms.dll ! System.Windows.Forms.Control.ControlNativeWindow。OnMessage(ref System.Windows.Forms.Message m) + 0x13 bytes
System.Windows.Forms.dll ! System.Windows.Forms.Control.ControlNativeWindow。WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes
System.Windows.Forms.dll ! System.Windows.Forms.NativeWindow.DebuggableCallback(系统。IntPtr hWnd, int msg, System。IntPtr wparam, System。IntPtr lparam) + 0x64字节[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll ! System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(系统。IntPtr dwComponentID, int reason, int pvLoopData) + 0x287 bytes
System.Windows.Forms.dll ! System.Windows.Forms.Application.ThreadContext。RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) + 0x16c bytes
System.Windows.Forms.dll ! System.Windows.Forms.Application.ThreadContext。runmessagelloop (int reason, System.Windows.Forms.ApplicationContext context) + 0x61字节
System.Windows.Forms.dll ! System.Windows.Forms.Application.Run (System.Windows.Forms。Form mainForm) + 0x31 bytes
BlueBall.Program.Main()第18行+ 0x1d字节c#[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll ! System.AppDomain。ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence, assemblySecurity, string[] args) + 0x6d字节
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2a bytes
mscorlib.dll ! System.Threading.ThreadHelper。ThreadStart_Context(object state) + 0x63 bytes
mscorlib.dll ! System.Threading.ExecutionContext.Run (System.Threading。ExecutionContext ExecutionContext, System.Threading.ContextCallback, callback, object state, bool ignoreSyncCtx) + 0xb0 bytes
mscorlib.dll ! System.Threading.ExecutionContext.Run (System.Threading。ExecutionContext ExecutionContext, System.Threading.ContextCallback回调,对象状态)+ 0x2c字节
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes
[Native to Managed Transition]

tcplistener does not start

Harold和Spender是正确的,TcpListener只能绑定到实例化它的机器上的本地IP地址。