My client cannot join server

When I try to join lobby I get the following error:

Trying to receive TimeSyncMessage from client 0 which is not in a connected state.
UnityEngine.Debug:LogWarning (object)
Unity.Netcode.NetworkMessageManager:GetMessageVersion (System.Type,ulong,bool) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Messaging/NetworkMessageManager.cs:523)
Unity.Netcode.NetworkMessageManager:ReceiveMessage<Unity.Netcode.TimeSyncMessage> (Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&,Unity.Netcode.NetworkMessageManager) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Messaging/NetworkMessageManager.cs:550)
Unity.Netcode.NetworkMessageManager:HandleMessage (Unity.Netcode.NetworkMessageHeader&,Unity.Netcode.FastBufferReader,ulong,single,int) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Messaging/NetworkMessageManager.cs:432)
Unity.Netcode.NetworkMessageManager:ProcessIncomingMessageQueue () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Messaging/NetworkMessageManager.cs:458)
Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkManager.cs:42)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkUpdateLoop.cs:185)
Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.5.1/Runtime/Core/NetworkUpdateLoop.cs:208)

However, client seems to be somehow in game because i get “2/20” on Lobby info, but stays just in the main menu…

Seems this is coming up more than once and it seems to be relating to a change to from udp to dtls.
Can you post your ClientGameManager script as it could be that the issue lies there as its the script we tackled in this lecture.

Thanks

/** ClientGameManager.cs **/

using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
using Unity.Networking.Transport.Relay;
using UnityEngine;
using UnityEngine.SceneManagement;
using Unity.Services.Core;
using Unity.Services.Authentication;
using Unity.Services.Relay;
using Unity.Services.Relay.Models;

public class ClientGameManager : IDisposable
{
    private JoinAllocation allocation;

    private const string MenuSceneName = "Menu";

    private NetworkClient networkClient;

    private UserData userData;

    public async Task<bool> InitAsync()
    {
        // Authenticate player
        await UnityServices.InitializeAsync();

        networkClient = new NetworkClient(NetworkManager.Singleton);

        AuthState authState = await AuthenticationWrapper.DoAuth();

        if (authState == AuthState.Authenticated)
        {
            return true;
        }

        return false;
    }

    public void GoToMenu()
    {
        SceneManager.LoadScene(MenuSceneName);
    }

    public async Task StartClientAsync(string joinCode)
    {
        try 
        {
            allocation = await Relay.Instance.JoinAllocationAsync(joinCode);
        }
        catch(Exception e)
        {
            Debug.Log(e);

            return;
        }

        UnityTransport transport = NetworkManager.Singleton.GetComponent<UnityTransport>();

        RelayServerData relayServerData = new RelayServerData(allocation, "dtls");

        transport.SetRelayServerData(relayServerData);

        userData = new UserData
        {
            userName = PlayerPrefs.GetString(NameSelector.playerNameKey, "Missing Name"),
            userAuthId = AuthenticationService.Instance.PlayerId
        };

        ConnectClient();
    }

    private void ConnectClient() 
    {
        string payload = JsonUtility.ToJson(userData);

        byte[] payloadBytes = Encoding.UTF8.GetBytes(payload);

        NetworkManager.Singleton.NetworkConfig.ConnectionData = payloadBytes;

        NetworkManager.Singleton.StartClient();
    }

    public void Dispose() 
    {
        networkClient?.Dispose();
    }
}

I cant see the any issue with the code here but i did have a student on Udemy that had a similar issue and it turned out to be a VPN causing the issue.

If you dont have a VPN then let me know and we can take a further look into why its not connecting the player in although they are clearly there in the lobby

Hi there!

Thank you for the prompt response and suggestion. Indeed, I was initially running a VPN during gameplay (Check Point), and I thought it might have been the cause of the problem. However, I’ve since shut the VPN down and unfortunately, the issue still persists.

Interestingly, even though I can’t see the client on the client-side during gameplay, I can confirm that he is present as I’ve been monitoring the server side. The client seems to appear as expected in the lobby, which adds to the perplexity of the situation.

Could this be due to some other networking or synchronization issue? I would greatly appreciate any further insight you might have. Thanks in advance!

The only thing i really can think of other than a code issue is that its a firewall exception blocking the connection to relay for the client and allowing it to actually instantiate into the game.
I would try adding some debug logs to see where it breaks down to see if we can pin down exactly in where in the code it might be.
I dont think its the timeout length as its stating its not in a connected state but yet its appearing in the lobby.

Let me know if you find anything and if not i can grab a copy of your project and take a look directly on this.

Well, it seems that switching from DTLS to UDP fixes the issue, then it may be an indication that there’s something with the DTLS protocol that’s causing connection issues.

DTLS (Datagram Transport Layer Security) and UDP (User Datagram Protocol) are both protocols for transmitting data over networks. However, DTLS has additional security features that UDP does not, which can make it more complex and potentially more prone to certain types of connection issues.

DTLS is designed to prevent eavesdropping, tampering, or message forgery. However, these additional security features can sometimes cause compatibility issues, or be blocked by certain types of network security settings. If my application works with UDP but not with DTLS, it’s possible that these security features are causing the issues.

I´ve also tried to deactivate my firewall and allow all network traffic and, with DTLS, it still didn’t work like it should.

I wonder if you download our project from the resources (You will have to hook up the project to UGS under your own account), if it will produce the same result.
If it does then we know that something with your ISP or something is not liking DTLS and if it works then we do need to check into your project to find out why DTLS is not working there and it does for our project.

At least this way we can rule out the external factors.

1 Like

Downloading the project and setting it up under my own UGS account didn’t solve the problem, so I must indeed suggest that the issue might lie with my ISP. As I’ve ruled out firewall, antivirus, and VPN services, it seems like my ISP may be blocking or not supporting DTLS. Some ISPs can restrict certain types of network traffic as part of their management policies.

I’ve also reviewed Unity’s documentation on networking and transport layers again to see if there are any additional steps or considerations when using DTLS but they also just mention UDP on client’s relay server data…

As so, i´ll continue the course using UDP… as it seems to be the only way for testing within the same network at least :slight_smile:

Thanks!

Hi scorpaust,

I was reviewing one of the final lectures in the mutiplayer teams section i encountered a different error which another student on Udemy stated was fixed when he switched back to UDP.
I’m yet to test if it solves my issue but i have passed the information to Nathan and a link to this thread so we can go back to Unity and see where the issue is as its looking like it could be ISP based.

Edit :- My error was something different in that my project link to UGS had become partially broken and logging out and back in of my account and refreshing the link solved the issue.

We are still contacting unity on the DTLS issue but we are adding a patch that if you encounter issues with DTLS to use UDP for now as it is related to ISP’s and security levels.

Update :-
If you get a moment can you please try something for me.

  1. Set the protocol back to dtls
  2. Do a server build and upload it
  3. Test the game and trigger the error
  4. Go to the dashboard and go to servers and on the one that is allocated click it and then check the multiplay logs.
  5. Download the log zip file
  6. Upload it to somewhere like google drive and post a link here.

Unity have asked if we can collect some log files of the servers as although they think its ISP related they would like to take a look to confirm this and see if they can resolve it.

Thanks for your help once again

Now it worked with 2 players on dedicated server using “dtls”… but still doesn’t work locally when using Host / Join Lobby…

Hi,

Sorry i meant to get back to this sooner but it slipped off my radar.
I am not sure why the dedicated server was playing up as the dtls is purely for the relay part as the dedicated server does not use it.

If you could supply those logs we can then forward them to unity and they can look into this further as they want to check to see if it really is an ISP issue or something else is the root cause and they can fix the issue.

Thanks in advance

Hi! Everything works fine in “Find Match” mode… but when it comes to Host / Client / Lobbies… the game freezes when client joins… but only when I use “dtls”.

Logs: server_64993979_logs_20230727103219.zip - Google Drive

Thanks :slight_smile:

Thank-you,

I’ve passed this along to Nathan this morning and via him we can contact the UGS team and they can look into it.
As soon as i get any update i will let you know but for now “udp” should work fine “dtls” is just a little more secure.

Thanks again for your help in this

Privacy & Terms