RevenantX / LiteNetLib

Lite reliable UDP library for Mono and .NET
https://revenantx.github.io/LiteNetLib/index.html
MIT License
3.06k stars 495 forks source link

LiteNetLib.NetManager.BindSocket(Socket socket, IPEndPoint ep), errorCode: AddressNotAvailable #537

Closed neonzz1 closed 10 months ago

neonzz1 commented 10 months ago

Information about bug or feature Server started on port 1234 [B]Bind exception: System.Net.Sockets.SocketException (10049): The requested address is not valid in its context. at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName) at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Bind(EndPoint localEP) at LiteNetLib.NetManager.BindSocket(Socket socket, IPEndPoint ep), errorCode: AddressNotAvailable

//Some c# code if needed
                Console.WriteLine("Server started on port 1234");

                EventBasedNetListener listener = new EventBasedNetListener();
                NetManager server = new NetManager(listener);
                server.DisconnectTimeout = 999999999;
                IPAddress ipa = IPAddress.Parse("86.142.232.220"); // works if localip is used socket not in use and port forwarded
                server.Start(ipa, IPAddress.IPv6Any, 1234);

Library version: [commit id (9f2a1d1a8244510d9ec502cc002bfdddba666d09) or release version (0.7.7.1)]

Framework: [dotnetcore]

OS: [Windows]

RevenantX commented 10 months ago

@neonzz1 you cannot bind socket to an external address if you not connected directly without router. This is how sockets works, this is not bug. Just use IPAddress.Any or just simple Start method with port.