How do I properly connect to a photon Realtime server using Unreal Engine?

I would like to start off with, no the Demo project didn't work and thus I had to try and figure it out with the very limited documentation found here: Realtime-Intro

After setting up a bunch of classes to try and get a basic setup running, I've come upon the issue that I never actually get to connect to the server. At first I thought I was sending to much data by calling the mLoadBalancingClient.Service() every frame. That is understandable and has been fixed but it seems the ConnectReturn in ExitGames::LoadBalancing::Listener never gets called. This subsequently also causes me to not be able to create rooms as I am not connected to the server.

Can anyone share some knowledge or knows what questions to ask me to try and help me out?

Best Answer

  • Kaiserludi
    Kaiserludi admin
    Answer ✓

    Hi @StereoJunkie.


    "Debug return: 2021-10-08 14:41:28,595 ERROR  WebSocketWindows.cpp      ExitGames::Photon::Internal::WebSocketConnect::connectAndReceive() 245  WinHttpWebSocketReceive: 12030"

    This line tells me multiple things:

    1) You are using the Windows Client SDK.

    2) You are using either ConnectionProtocol::WS or ConnectionProtocol::WSS or UDP in combination with 'tryUseDatagramEncryption', as otherwise WebSockets would not be used.

    3) You are on a 5.0.0.x version of the Client SDK, as the 4.1.x.x versions don't support WS/WSS on Windows nor do they support 'tryUseDatagramEncryption'.

    4) Your connection attempt fails with an ERROR_WINHTTP_CONNECTION_ERROR error response (see https://docs.microsoft.com/en-us/windows/win32/winhttp/error-messages).


    Point 3) gives me an idea about what your issue with the Unreal demo project is:

    That demo project still expects an 4.1.16.x SDK to be used. Please see https://forum.photonengine.com/discussion/18903/cant-build-photondemoparticle-ue4 for instructions about the small changes that need to be made in the demo project to make it build against 5.0.0.x SDKs.

    Furthermore please make sure that you have switched the Unreal version of the project to a version that you have installed (by right-clicking on the .uproject file in the Windows explorer and selecting the according option from the context menu).


    Regarding your own project:

    You might try to run it with UDP in combination with 'tryUseDatagramEncryption' set to false and see if you can get a connection that way. Also you might attempt with TCP as well.

    That might give us further insight on the issue.


    I didn't know for sure if I needed authentication values or not but the demo seems to use it.

    You should set an userID, but you should not set an auth type or anything else on the authentication values, unless you have actually set-up an auth service for your appID in the dashboard.


    So I got the demo working

    That means that your firewall and router settings are not the culprit, as otherwise the demo would fail to connect as well.


    Please make sure that service() is called regularly. From the little code that I have seen so far I don't see any other potential reason why your project would not connect, while the demo connects.

Answers

  • Hi @StereoJunkie.

    I would like to start off with, no the Demo project didn't work

    Yes, the demo project DOES work. I suggest you point out what issues you are actually run into with the demo project, so that I can point you into the right directions to make it work for you as well.


    At first I thought I was sending to much data by calling the mLoadBalancingClient.Service() every frame.

    That certainly can't be the issue. A call to service() only results in data being sent if there actually is any data to send. As you are not even connected yet, service() can't send anything except the connect-request. It won't repeat that request in every single call. So calling it that often in your situation will only result in service() checking more often if there is anything for it to do, but not in it sending more data. While in general it is usually preferable for most games to only call service() 10-20 times per second, calling it every frame works as well. It only prevents Photon from aggregating data over multiple frames before sending it to the server, which can result in more protocol overhead if you queue lots of small messages for sending.

    Can anyone share some knowledge or knows what questions to ask me to try and help me out?

    First make sure that you actually pass a valid appID to the Photon Client.

    Next I would recommend to get either the Unreal the demo working for you or to run one of the command-line demos from within the 'Demos' folder of the SDK so that you can see if the demo can connect.

    If the demo can't connect either, then it is most likely an issue with your firewall or router blocking the connection. In that case please check their settings to make sure that they let Photons traffic through.

    You can see a list of the port numbers here:

    https://doc.photonengine.com/en-us/realtime/current/connection-and-authentication/tcp-and-udp-port-numbers

    If you use UDP and do not pass 'true' for 'useAlternativePorts' nor for 'tryUseDatagramEncryption', then ports 5055-5058 are the ones, that you need to enable. With alternative ports, 27000-27002 are the ones that you need to allow. With datagram encryption, you need to allow ports 5055 and 5056 for UDP and port 19093 for TCP. With TCP you need to allow ports 4530-4533, with WS ports 9090-9093 and with WSS 19090-19093.


    If the demo can connect, then you can simply track down the source of the connection problem in your code by comparing it with the demo and figuring out what it does differently.


    Also I recommend to set the DebugLevel on 'mLoadBalancingClient' to at least 'INFO' to get more log output, and to print that output somewhere where you can inspect it, in your implementation of debugReturn() as that output might give hints about what the problem is.

  • Tomorrow I'll try the console based demo. The issue with the Unreal Engine demo was that no matter if I had VS 2015 or the UE4 version that the project was made in the project wouldn't rebuild itself. There probably is a way to fix it but that time is not available to me so I had to get to experimenting myself.

    Thank you for the info, you've been of very great help. I'll keep in touch about what I find is the issue!

  • So I got the demo working and I'm trying to adapt my unreal project to do the same but the listener doesn't seem to get the connect return called. (Nor any of the other returns) So I am unsure what I am doing wrong with the setup/connect. I don't have much code to show but this is basically it.

    I didn't know for sure if I needed authentication values or not but the demo seems to use it.

  • Ok so even when adding the extra debugging logging it, the only return method that gets called is the debug return.

    The debug I give back states:

    "Debug return: 2021-10-08 14:41:28,595 ERROR  WebSocketWindows.cpp      ExitGames::Photon::Internal::WebSocketConnect::connectAndReceive() 245  WinHttpWebSocketReceive: 12030"

  • Kaiserludi
    Kaiserludi admin
    Answer ✓

    Hi @StereoJunkie.


    "Debug return: 2021-10-08 14:41:28,595 ERROR  WebSocketWindows.cpp      ExitGames::Photon::Internal::WebSocketConnect::connectAndReceive() 245  WinHttpWebSocketReceive: 12030"

    This line tells me multiple things:

    1) You are using the Windows Client SDK.

    2) You are using either ConnectionProtocol::WS or ConnectionProtocol::WSS or UDP in combination with 'tryUseDatagramEncryption', as otherwise WebSockets would not be used.

    3) You are on a 5.0.0.x version of the Client SDK, as the 4.1.x.x versions don't support WS/WSS on Windows nor do they support 'tryUseDatagramEncryption'.

    4) Your connection attempt fails with an ERROR_WINHTTP_CONNECTION_ERROR error response (see https://docs.microsoft.com/en-us/windows/win32/winhttp/error-messages).


    Point 3) gives me an idea about what your issue with the Unreal demo project is:

    That demo project still expects an 4.1.16.x SDK to be used. Please see https://forum.photonengine.com/discussion/18903/cant-build-photondemoparticle-ue4 for instructions about the small changes that need to be made in the demo project to make it build against 5.0.0.x SDKs.

    Furthermore please make sure that you have switched the Unreal version of the project to a version that you have installed (by right-clicking on the .uproject file in the Windows explorer and selecting the according option from the context menu).


    Regarding your own project:

    You might try to run it with UDP in combination with 'tryUseDatagramEncryption' set to false and see if you can get a connection that way. Also you might attempt with TCP as well.

    That might give us further insight on the issue.


    I didn't know for sure if I needed authentication values or not but the demo seems to use it.

    You should set an userID, but you should not set an auth type or anything else on the authentication values, unless you have actually set-up an auth service for your appID in the dashboard.


    So I got the demo working

    That means that your firewall and router settings are not the culprit, as otherwise the demo would fail to connect as well.


    Please make sure that service() is called regularly. From the little code that I have seen so far I don't see any other potential reason why your project would not connect, while the demo connects.

  • The issue was the datagram encryption. Thank you so much for helping! You saved me a lot of troubleshooting.

  • Hi @StereoJunkie.

    So it works in the demo with datagram encryption and in your project only without it?

    Or did you try it with a demo that does not use datagram encryption on default and turning it on makes the demo also not connect for you?


    If it doesn't work with datagram encryption for the demo either, then that would indicate that TCP traffic on port 19093 is blocked by either either your firewall or router and adjusting their settings accordingly should make datagram encryption work for you as well.


    Of course, if encryption of all network traffic isn't a feature that you want or need, then you could just leave it turned of.


    Or if you are still in the evaluation phase, then it might make sense to play around with Photon without datagram encryption for now and to look into it at a later point, even if you want to use it.