C#SocketException未处理 - 聊天服务器 [英] C# SocketException was unhandled - Chat Server
问题描述
大家好, 我的聊天程序存在很大问题。您可以在下面找到我收到错误的代码。代码中没有错误或编译。但只有当程序运行并且达到平衡时...... 一些额外的信息: 当你按下按钮时设置ipAddress ;开始听"。您在文本框中填写的IP地址在ipAddress中设置。 这里我的错误:
System.Net.Sockets.SocketException未处理
Message =" Het aangevraagde adres is niet geldig in de context van het adres"
来源="系统"
ErrorCode = 10049
NativeErrorCode = 10049
StackTrace:
bij System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot,SocketAddress socketAddress)
bij System.Net。 Sockets.Socket.Bind(EndPoint localEP)
bij System.Net.Sockets.TcpListener.Start(Int32 backlog)
bij Chat_Server.Chatserver.StartListening()in C:\ Users \Yamotos \ Documents\Visual Studio 2008 \OwnProjects \Chat Server \ Server Server \ChatServer.cs:regel 190
bij Chat_Server.Form1.btnListen_Click(Object sender,EventArgs e)in C:\ Users \ Yamotos \Documents\Visual Studio 2008 \OwnProjects\Chat Server \ Server Server \ Form1.cs:regel 34
bij System.Windows.Forms.Control.OnClick(EventArgs e)
bij System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bij System.Windows.Forms.Control.WmMouseUp(Message& m,MouseButtons button,Int32 clicks)
bij System.Windows.Forms。 Control.WndProc(消息和; m)
bij System.Windows.Forms.ButtonBase.WndProc(Message& m)
bij System.Windows.Forms.Button.WndProc(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows .Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)
bij System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bij System.Windows.Forms.Application .ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,Int32 reason,Int32 pvLoopData)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)
bij Chat_Server.Program.Main()in C:\ Users \Yamotos \ Files \ VisualVisual Studio 2008 \\ \\OwnProjects \Chat Server \ Server Server \ Program.cs:regel 18
bij System.AppDomain._nExecuteA ssembly(Assembly assembly,String [] args)
bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state)
bij System.Threading.ThreadHelper.ThreadStart()
InnerException:
这里代码的安静:
//获取第一个网络设备的IP,但这在某些配置上可能不可靠
IPAddress ipaLocal = ipAddress;
//使用服务器的IP和指定的端口创建TCP侦听器对象
tlsClient = new
TcpListener(ipAddress,1986);
//启动TCP监听器并监听连接
tlsClient.Start();
解决方案
你好,
首先我想请你看看这个
链接。有一些关于如何解决这个问题的答案第二,有一个MSDN示例应用程序异步服务器套接字示例
其他如果您需要任何帮助,还有另一个带有UI的微软示例称为异步套接字
在哪里。
这可以帮助您解决所有问题。
最好的问候,
Emanuel Varga
Hello all,
I have got a huge problem with my chat program. Below you can find the code where I got a error. There are no errors in the code or with compiling. But only when the program is running and going to that peace...
Some extra information:
ipAddress is set when you press the button "start listening". The Ip Address that you fill in in a textbox, is set in ipAddress.
Here my error:
System.Net.Sockets.SocketException was unhandled
Message="Het aangevraagde adres is niet geldig in de context van het adres"
Source="System"
ErrorCode=10049
NativeErrorCode=10049
StackTrace:
bij System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
bij System.Net.Sockets.Socket.Bind(EndPoint localEP)
bij System.Net.Sockets.TcpListener.Start(Int32 backlog)
bij Chat_Server.Chatserver.StartListening() in C:\Users\Yamotos\Documents\Visual Studio 2008\OwnProjects\Chat Server\Chat Server\ChatServer.cs:regel 190
bij Chat_Server.Form1.btnListen_Click(Object sender, EventArgs e) in C:\Users\Yamotos\Documents\Visual Studio 2008\OwnProjects\Chat Server\Chat Server\Form1.cs:regel 34
bij System.Windows.Forms.Control.OnClick(EventArgs e)
bij System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bij System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bij System.Windows.Forms.Control.WndProc(Message& m)
bij System.Windows.Forms.ButtonBase.WndProc(Message& m)
bij System.Windows.Forms.Button.WndProc(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bij System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bij System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bij Chat_Server.Program.Main() in C:\Users\Yamotos\Documents\Visual Studio 2008\OwnProjects\Chat Server\Chat Server\Program.cs:regel 18
bij System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bij System.Threading.ThreadHelper.ThreadStart()
InnerException:
Here the peace of my code:
// Get the IP of the first network device, however this can prove unreliable on certain configurations
IPAddress ipaLocal = ipAddress;
// Create the TCP listener object using the IP of the server and the specified port
tlsClient = new
TcpListener(ipAddress, 1986);
// Start the TCP listener and listen for connections
tlsClient.Start();
解决方案 Hello,
First i would like to ask you to take a look at this
link . There are some answers there on how to fix this problem.
Second, there is an MSDN Sample application Asynchronous Server Socket Example
here if you need any help and also another microsoft example with UI called Asynchronous Sockets
here .
This should help you solve all of your problems.
Best Regards,
Emanuel Varga
这篇关于C#SocketException未处理 - 聊天服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文