简体   繁体   English

Lidgren 第二次创建服务器实例导致 System.Net.Sockets.SocketException

[英]Lidgren create server instance for a second time results in System.Net.Sockets.SocketException

I am using Lidgren in Monogame.我在 Monogame 中使用 Lidgren。 There is a possibility that a player would want to host a game, then exits the lobby, and wants to host again.玩家有可能想要主持一场比赛,然后离开大厅,并想再次主持。 However, when I do this in my code, the following exception is raised: System.Net.Sockets.SocketException: 'Only one usage of each socket address (protocol/network address/port) is normally permitted'但是,当我在我的代码中执行此操作时,会引发以下异常: System.Net.Sockets.SocketException: '每个套接字地址(协议/网络地址/端口)通常只允许使用一次'

Relevant code:相关代码:

// initializing the server
NetPeerConfiguration _config = new NetPeerConfiguration("some app id");
// code to enable certain messages.
_server = new NetServer(_config);
_server.Start();

// cleaning up the server instance
_server.Shutdown("server shutdown");
_server = null;

The code crashes at _server.Start() with binding the socket.( m_socket.Bind() ).代码在_server.Start()处因绑定套接字而崩溃。( m_socket.Bind() )。

How can I clean the server/socket up so that I can create a new instance of the server a second time around?如何清理服务器/套接字,以便再次创建服务器的新实例?

The cause of this is an improper shutdown of the previous server's instance meaning the port is still in use by that instance.造成这种情况的原因是前一个服务器实例的不正确关闭,这意味着该端口仍在被该实例使用。 Seems to have been a bug, the internal cleanup didn't work properly https://github.com/lidgren/lidgren-network-gen3/issues/94 https://github.com/lidgren/lidgren-network-gen3/issues/94#issuecomment-369561026 however it was fixed so be sure to have the latest version of lidgren-network https://github.com/RevoluPowered/lidgren-network/tree/feature/socket-overhaul似乎是一个错误,内部清理工作不正常https://github.com/lidgren/lidgren-network-gen3/issues/94 https://github.com/lidgren/lidgren-network-gen3/问题/94#issuecomment-369561026但是它已修复,因此请确保拥有最新版本的lidgren-network https://github.com/RevoluPowered/lidgren-network/tree/feature/socket-overhaul

you can use _server.Socket.Close();你可以使用_server.Socket.Close(); just to be sure the socket closes before starting another server or instance.只是为了确保套接字在启动另一个服务器或实例之前关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Net.Sockets.SocketException - System.Net.Sockets.SocketException 创建WebSocket连接时出现System.Net.Sockets.SocketException - System.Net.Sockets.SocketException when create a websocket connection 2008R2服务器上的System.Net.Sockets.SocketException - System.Net.Sockets.SocketException on 2008R2 Server postgres 连接上的 System.Net.Sockets.SocketException - System.Net.Sockets.SocketException on postgres connection System.Net.Sockets.SocketException 灾难 - System.Net.Sockets.SocketException Disaster .NET服务System.Net.Sockets.SocketException:'未知此类主机' - .NET Service System.Net.Sockets.SocketException: 'No such host is known' C# HttpClient多个Get请求同时给出System.Net.Sockets.SocketException(10060)异常 - C# HttpClient Multiple Get Requests at the same time giving System.Net.Sockets.SocketException (10060) Exception 使用Azure时Visual Studio中的System.Net.Sockets.SocketException - System.Net.Sockets.SocketException in Visual Studio while using Azure System.Net.Sockets.SocketException:'提供了无效的参数' - System.Net.Sockets.SocketException: 'An invalid argument was supplied' System.Net.Sockets.SocketException(0x80004005) - System.Net.Sockets.SocketException (0x80004005)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM