我是新来的C#网络和我有一些麻烦,使一个基本的客户端 - 服务器。服务器运行良好,但是当服务器启动并且客户端尝试连接时,会抛出错误“该套接字不能被绑定或连接”。一些额外的细节是服务器和客户端在禁用exclusiveAddressUse的同一台计算机上运行。TCP套接字 - InvalidOperationException
客户端代码:
this.client = new TcpClient(this.settings.GetByName("MasterServerIP").Value, int.Parse(this.settings.GetByName("MasterServerPort").Value)) { ExclusiveAddressUse = false };
this.client.Connect(IPAddress.Parse(this.settings.GetByName("MasterServerIP").Value), int.Parse(this.settings.GetByName("MasterServerPort").Value));
this.writer = new BinaryWriter(this.client.GetStream());
this.reader = new BinaryReader(this.client.GetStream());
Server代码:
this.Listener.Start();
TcpClient tcpClient;
while (this.Listener.Server.Connected)
{
tcpClient = this.Listener.AcceptTcpClient();
System.Threading.Thread t = new System.Threading.Thread(() => { this.ProcessClient(tcpClient); }); //Runs the thing on another thread so this can be accepting another client
t.Start();
}
编辑:即使在连接方法调用删除,它仍然抛出了同样的错误。任何帮助?
请不要编辑您的问题以删除相关的细节。提高信息是可以的,但是要做出改变,使迄今为止所有答案无效,从而“打破”问答概念。 – paxdiablo
对不起,我只是以为我会删除它,所以人们不再指出这一点(因为他们没有看到答案) – user1763295
没关系,只是在问题的末尾添加一个编辑,看起来似乎是错误的没有第二个连接,并且错误在构造函数调用中。并给我们从socketexception实际的错误号码:-) – paxdiablo