How can i make a handshake between two clients using a relay server?

[TL/DR] How/where can i start a handshake between two players that communicate through a relay server?

I have been since last year (ha!) trying to solve this puzzle.
I’m looking for a way that two players get connected through a nodejs server, so they both make a handshake and i can use the replication system from UE4.
i have override uIpnetdriver and trying to extend it and modify. So far what i have achieve is that when a client create a map with listen and other with connect both get connected to the relay server.
Now the client that is trying to connect to listen server is sending handshaking packages through the relay server to the client in listen mode.

The problem is that i can’t find a way that the listen client receive that package and begin the handshaking process. I have been trying to access some functions and properties, but, i can’t get further because they are private, so i cant access to their members/functions.

So the main question is How/where can i start a handshake between two players that communicate through a relay server?

In its simplest form, a multiplayer game requires some sort of server/authority. It doesn’t matter who or where that is, as long as it’s there to keep track of its clients. For non-UE servers I’ve seen this article to be useful A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums

Yes , as i said before, im trying to implement a Listen Server model with a relay server

oh, I see. Do you plan to have an exclusive in-house solution? or are you open for third-party solutions. I know Microsoft Azure has such service available, for example, that I’ve used in the past.

Do not get confused in Listen Server and Relay Server connection. You are using UE4 Listen server mode, in which your client who is starting in Listen server mode, act as a server and also a client (which is authoritative), both of the clients should have replicated properties enabled to see the data changes on server happening, also only server should be allowed to change the values, only then they will be replicated to each clients, not the other way around.

If you want to connect your server to your own, you should not use listen server mode, instead use dedicated server

Maybe i didn’t make myself clear
I Have client A and Client B. They want to start a vs online match. They both use a mobile phone for it.
Escenario 1:
1-Client A start hosting a game as Listen Server
2- Client B tries to connect to client A using Client A IP address and port.

This setup works only if they are under a LAN or same wifi network. For Internet / mobile data connections this setup does not work because NAT. That’s why i need a relay server

Escenario 2

1-Client A start hosting as Listen Server and notifies Remote Server about his state.
2- Client B tries to connect to client A using Client A Ip.
3- Client B sends packet to Remote Server. Remote server grab the package and send it back to Client A
4 -Client A gets Client B package, check magic header and stuff , make the handshake and send data back to Client B through Remote Server.
5- At this point Client A and Client B are sending packages each other through Remote Server. by passing Nat.

I want to use UE4 replication solution instead of coding my own
I want to avoid any solution that require to ask the client open their ports. In mobile that is just saying goodbye to your client.
Using a Dedicated server for a 1v1 game is overkill and expensive.

Right now i have achieved the communication between A and B, but i can’t find a way that Listen-server accepts B handshake and begin the game. and makes CLient B begin the game

There are people who have achieved the functionality which you are trying to create through a dedicated server of their own, generally they have used AWS for this as its quite extensible. But then you can also host your own server on your static IP and try connecting it to the client.

Also steam works also gives free server for testing it seems, you can use them as well.
OR else use some free cloud hosting server, host your UE4 server there and connect to it.

My problem is not the Server (relay server)
my problem is how to make the Listen-server and Client communicate the handshaking and game status through this tunnel.

Maybe I don’t understand what you are trying to do but will this not work:

  1. Client A starts Listen server
  2. Listen server uses a STUN service to get the external IP and Port and reports it to the nodejs server.
  3. Client B gets the IP and port from the nodejs server and connects to the listen server

Actually my first approach was using stun to discover ip and port, but it didn’t work in some cases. thats why i m trying to use the Turn approach.

I think this is the key: the client initiates the connection. This way NAT is not the problem. Perhaps you can do some tests:

I heard STUN works on WebRTC and Unreal Engine also uses it. They have implemented a webRTC server in Pixel streaming feature. You can search about it there. Also share some insights when you found, would love to explore it :slight_smile:

“For convenience, the Unreal Engine also ships with binary versions of the STUN and TURN reference servers that are defined in the C++ WebRTC SDK. You can find these in the Engine/Source/ThirdParty/WebRTC/rev.23789/programs/Win64/VS2017/release folder under your Unreal Engine install location. These implementations may not offer production-grade reliability, but they may help you get started.”


Free server open for anyone like to connet and show your UE4 project., easily just setup Parameters from

Unreal Editor, Under the Level Editor > Play category, find the Additional Launch Parameters setting, and set its value to -AudioMixer -PixelStreamingIP= -PixelStreamingPort=8889.

More detail please check step how to connect free server

follow us…gin-developing

Did you end up having it working? Im curios about it, Im developing against EOS which offers the NAT functionality for free but Im pretty sure there is a hard limit on the relay piece (mobile connection) which I cant find BTW