I am using Lidgren in Monogame. 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'
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()
).
How can I clean the server/socket up so that I can create a new instance of the server a second time around?