Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Cannot connect to Relay server

Discussion in 'Multiplayer' started by ali4langi1899, May 30, 2023.

  1. ali4langi1899

    ali4langi1899

    Joined:
    Aug 30, 2020
    Posts:
    3
    Guys, I use Relay and Lobby in my project and it works fine with ordinary internet (like cellular data).
    Still, for some internet connections like schools and universities in which there are restrictions, it cannot connect to Relay. (the connection type is UDP, I have already tried DTLS)
    It just says it cannot connect to the server, and sometimes it doesn't show any error but cannot connect and start the Relay. but it works fine for Lobby.
    Also, the weird thing is for those restricted networks, it finds Asia as the best server, while I'm in Italy. But with ok internet connections, it works fine and it connects to a German server.

    Any solutions?
    I'd appreciate your help
     
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    416
    It's possible that those restricted networks are blocking the UDP ports used by the Relay service. The Relay service uses a random UDP port in the range 37000-37100 for communications, and the QoS service (which selects the best server to connect to) uses UDP port 7778. You should ensure that these ports are open for outgoing communications in these restricted networks.

    You could also investigate using WebSockets instead of UDP or DTLS. Since WebSockets are TCP-based, they might have a more lenient policy in these restricted networks. To use WebSockets, you need to be on 2022.2 or later and install version 2.0 of the
    com.unity.transport
    package (latest version is 2.0.1). Then, check the "Use WebSockets" checkbox under the Unity Transport component and use "wss" as the connection type when building the Relay server data.
     
  3. ali4langi1899

    ali4langi1899

    Joined:
    Aug 30, 2020
    Posts:
    3
    I really appreciate your answer. I have relayed your information to the technicians of the school.

    unfortunately, I am using 2021.3.20f1 and cannot use the last option you said. I might use it as my final choice.

    But generally, Can you please guide me about the different types of connection in Relay and when to use them?
    For example, how should I know the connection type in Unity uses what range of ports? or anything related to background of the Relay
     
    Last edited: Jun 3, 2023
  4. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    416
    The range of port should be the same no matter the connection type. The only difference will be that if using UDP or DTLS, the ports will be UDP, and if using WebSockets, the ports will be TCP. The QoS service always uses UDP port 7778 no matter what the connection type is.

    Regarding what the different connection types are:
    • UDP ("udp") is the default and would generally be the most performant.
    • DTLS ("dtls") is just UDP with encryption on top. If you're worried about important information being sniffed from the traffic, you should use that.
    • WebSockets ("wss") is newer (requires Unity 2022.2 or later and Transport 2.0) and is the only connection type supported on browsers (WebGL). It's based on TCP and is always encrypted.
    Does that answer your question?
     
  5. travis-TAP-3D

    travis-TAP-3D

    Joined:
    Sep 12, 2022
    Posts:
    22
    Sorry to revive an old thread @simon-lemay-unity , but this is super critical information and much appreciated as we try to get Relay to work in school and enterprise networks. Any particular reason this isn't documented anywhere vs buried in the forums? Thanks again!
     
  6. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    416
    I'm not sure why this isn't documented. I'll bring it up with the team. Thanks for the feedback.
     
  7. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    416
    @travis-TAP-3D All ports and protocols should be documented in this article. Is there any information not present there that you think should be included?