RiptideNetworking / Riptide

Lightweight C# networking solution for multiplayer games.
https://riptide.tomweiland.net
MIT License
1.04k stars 141 forks source link

Unhandled SocketException while Client with no Internet Connection tries to connect to the server. #101

Closed Bilnord closed 6 months ago

Bilnord commented 1 year ago

Client with no Internet Access trying to connect to the server will get unhandled SocketException leading to not invoking ConnectionFailed event.

SocketException: An attempt was made to perform a socket operation on an unreachable network.
System.Net.Sockets.Socket.SendTo (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint remoteEP) (at <aa976c2104104b7ca9e1785715722c9d>:0)
System.Net.Sockets.Socket.SendTo (System.Byte[] buffer, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint remoteEP) (at <aa976c2104104b7ca9e1785715722c9d>:0)
Riptide.Transports.Udp.UdpPeer.Send (System.Byte[] dataBuffer, System.Int32 numBytes, System.Net.IPEndPoint toEndPoint) (at <38554de8f79d4966aa6f152e783b5fe7>:0)
Riptide.Transports.Udp.UdpConnection.Send (System.Byte[] dataBuffer, System.Int32 amount) (at <38554de8f79d4966aa6f152e783b5fe7>:0)
Riptide.Connection.Send (Riptide.Message message, System.Boolean shouldRelease) (at <38554de8f79d4966aa6f152e783b5fe7>:0)
Riptide.Client.Send (Riptide.Message message, System.Boolean shouldRelease) (at <38554de8f79d4966aa6f152e783b5fe7>:0)
Riptide.Client.Heartbeat () (at <38554de8f79d4966aa6f152e783b5fe7>:0)
Riptide.Client.Connect (System.String hostAddress, System.Int32 maxConnectionAttempts, System.Byte messageHandlerGroupId, Riptide.Message message, System.Boolean useMessageHandlers) (at <38554de8f79d4966aa6f152e783b5fe7>:0)
Bilnord commented 1 year ago

Also when Client will successfully connect and then disable the WiFi/Cellular Data or just Network Connection on PC it will throw the exception caused by Client.Update() leading to Socket.SendTo .

Bilnord commented 1 year ago

Pull request #102