BeardedManStudios/ForgeNetworkingRemastered

Only tries to connect once

roa-nyx opened this issue · 2 comments

Version Number and Operating System(s):

Version 26 from the asset store (Mar 20, 2019), Windows 10 1903

Expected behavior:

Attempt to connect to server 10 times with 3 second delays between attempts. If server is unreachable trigger connectAttemptFailed event on UDPClient.

Actual behavior:

//Snippet from UDPClient.Connect
				Task.Queue(() =>
				{
					do
					{
						// Send the accept headers to the server to validate
						Client.Send(connectHeader, connectHeader.Length, Server.IPEndPointHandle);
						Thread.Sleep(3000);
					} while (!headerExchanged && IsBound && ++connectCounter < CONNECT_TRIES);

					if (connectCounter >= CONNECT_TRIES)
					{
						if (connectAttemptFailed != null)
							connectAttemptFailed(this);
					}
				});

Attempts to connect once, a SocketException occurs in UDPClient.ReadNetwork, which triggers Disconnect(true) which ultimately results in IsBound on the client to be set to false, which pre-empts any further connection attempts.

Additionally because the connectCounter never increments, the connectAttemptFailed is never triggered.

Steps to reproduce:

			comm = new UDPClient();
			comm.connectAttemptFailed += clientConnectFailed;
			comm.serverAccepted += clientConnected;
			comm.bindFailure += clientBindFailure;
			comm.Connect("127.0.0.1", 9789);

Make sure to create your own clientConnectFailed, clientConnected and/or clientBindFailure functions to use this test code.

#180 seems to indicate this is in some way related to IP parsing? But I'm not seeing how. In my case I'm trying to connect to 127.0.0.1.

Already fixed in #315

@andreivreja thanks for the quick response! I'll apply that patch to my code in the mean time.