BeardedManStudios / ForgeNetworkingRemastered

See various forks, also please join the Forge Community fork of Forge Alloy! -> https://github.com/ForgeAlloyCommunity/ForgeAlloy
https://twitter.com/FarrisFaulds
Apache License 2.0
1.49k stars 306 forks source link

Only tries to connect once #318

Closed roa-nyx closed 5 years ago

roa-nyx commented 5 years ago

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.

andreivreja commented 5 years ago

Already fixed in https://github.com/BeardedManStudios/ForgeNetworkingRemastered/pull/315

roa-nyx commented 5 years ago

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