[C++ Networking] How to get a client connection event?

Hi everyone,

We’re making a muliplayer networked game, and for now, we do have our client and server. We are’nt using custom socket system for now.

Is there a way to catch a client connection event ? Or a way to get the current socket used by the default server ?
Or we have to make ourselves a whole network system in C++ ?

We’re pretty newbie in UE4 development, and didn’t find anything on the AnswerHub for us :frowning:

Thanks !

To catch the moment when a new connection is made is by hooking into the NotifyAcceptedConnection method of UWorld or AOnlineBeacon. They both manage an UNetDriver and inherit from FNetworkNotify.

Another point to catch when a new connection is being linked to a player controller could be OnActorChannelOpen from AActor. This one is the client side place where the PC binds itself to a local viewport, so from there you could notify the server about the connection.

Yet another way is to use the login chain within the GameMode, there you got PreLogin, Login and PostLogin, those are commonly used to reject entering players and do some initial setup. You can start calling replication methods on the PlayerController from PostLogin but not in PreLogin nor Login, while you can reject an entering player in PreLogin or Login specifying an error if you like, for example if the game is full.

So now you just have to play around with all those and pick the one that suits you best.


1 Like

Wow, really, thank you for your fast answer ! :slight_smile:
We’ll test that, but I think it will be ok !

Thank’s a lot !

Nice! Don’t forget to accept the answer if it fixed you issues, so we help to make this community even better!