# Realtime Multiplayer in UE4

**URL:** <https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604>\
**Category:** Local Setup\
**Tags:** sdk-unreal\
**Created:** [April 30, 2021, 4:03pm UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604 "2021-04-30T16:03:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![SnappierSoap318](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/snappiersoap318/32/627_2.png) [@SnappierSoap318](https://forum.heroiclabs.com/u/SnappierSoap318)\
**Post date:** [April 30, 2021, 4:03pm UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604/1 "2021-04-30T16:03:15Z")

</div>

How can i setup basic server sided code for allowing players to join the map?  
i have implemented the client side Matchmaking by referencing [Matchmaker](https://heroiclabs.com/docs/gameplay-matchmaker/), but how do i do the server sided setup so that the player can join the map when the matchmaker find them a match

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [April 30, 2021, 6:48pm UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604/2 "2021-04-30T18:48:59Z")

</div>

Hey @SnappierSoap318 👋 keep in mind that you don’t need to write any server-side code to do matchmaking and join the resulting match.

I’d get it working without using our server-side hooks first just to become familiar with the basic flow.

Since you already have the matchmaker call, you’ll want to listen to implement `onMatchmakerMatched` in the `NRtClientListenerInterface` and inside the implementation call `rtClient->joinMatch` using the match ID passed to the call.

If you do decide to add custom server-side logic, take a look at the server runtime hooks: [Function Reference - Nakama server](https://heroiclabs.com/docs/runtime-code-function-reference/#register-hooks)

---

<div class="post-metadata">

**Author:** ![SnappierSoap318](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/snappiersoap318/32/627_2.png) [@SnappierSoap318](https://forum.heroiclabs.com/u/SnappierSoap318)\
**Post date:** [May 3, 2021, 11:05am UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604/3 "2021-05-03T11:05:55Z")

</div>

so @lugehorsam, on the client side, i have written the `rtClient->joinMatch` but when it recieves the matchID, what does it do next, like does the `joinMatch` method automatically change the level from UI to playstate? or should we implement that on the client side?

---

<div class="post-metadata">

**Author:** ![SnappierSoap318](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/snappiersoap318/32/627_2.png) [@SnappierSoap318](https://forum.heroiclabs.com/u/SnappierSoap318)\
**Post date:** [May 3, 2021, 11:09am UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604/4 "2021-05-03T11:09:13Z")

</div>

Also how does the Matchmaker know which server to allocate in order to connect the clients which are placed in a match together?

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [May 3, 2021, 3:18pm UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604/5 "2021-05-03T15:18:57Z")

</div>

@SnappierSoap318 you will need to implement that on the client side. You use the matchId to send match data between the clients.

In terms of which server to allocate, this isn’t something you need to worry about if you are using Heroic Cloud. If you are running the server locally, this also isn’t an issue since only one node is running.

---

<div class="post-metadata">

**Author:** ![SnappierSoap318](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/snappiersoap318/32/627_2.png) [@SnappierSoap318](https://forum.heroiclabs.com/u/SnappierSoap318)\
**Post date:** [May 4, 2021, 8:08am UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604/6 "2021-05-04T08:08:39Z")

</div>

@lugehorsam, I need to replicate data through nakama instead of the Unreal Subsystem?

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [May 4, 2021, 11:08am UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604/7 "2021-05-04T11:08:56Z")

</div>

@SnappierSoap318 like any server, any data you want to persist across devices needs to go through Nakama.

---

<div class="post-metadata">

**Author:** ![SnappierSoap318](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/snappiersoap318/32/627_2.png) [@SnappierSoap318](https://forum.heroiclabs.com/u/SnappierSoap318)\
**Post date:** [May 4, 2021, 11:23am UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604/8 "2021-05-04T11:23:33Z")

</div>

@lugehorsam, We have already finished replication through UE and have a headless server setup. We can connect to it through the `open <ip-address>` command. So when I join through that command, I see all the other players replicated, so how will I do the same thing through namaka?

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [May 4, 2021, 4:27pm UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604/9 "2021-05-04T16:27:28Z")

</div>

@SnappierSoap318 take a look at the Nakama console on port 7351, sign in and you’ll see an option to view all players that have authenticated with Nakama, as well as a variety of other information.

---

<div class="post-metadata">

**Author:** ![SnappierSoap318](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/snappiersoap318/32/627_2.png) [@SnappierSoap318](https://forum.heroiclabs.com/u/SnappierSoap318)\
**Post date:** [May 4, 2021, 4:44pm UTC](https://forum.heroiclabs.com/t/realtime-multiplayer-in-ue4/1604/10 "2021-05-04T16:44:29Z")

</div>

@lugehorsam, Yes, I can see that, but I don’t need that information. what i want to know is

1. I have written all the client side code for joining, matchmaking, creating etc. but how does the player actually join a server(ie through ip? or auto executing a command?)
2. how does the server( headless UE) know which players to accept when a match is created
3. How does nakama know what server to connect to? ( How do we add the headless a server node to Nakama so that the matchmaker can assign the servers?)
4. Do we need to do the replication through Nakama or through UE’s internal system?
