Send message to open port in a server

Hello everyone,

We have a server opened in a specific port and I want to be able to send messages to that port from an external program.

However i cant get that program to connect to the server’s port. The first solution i came up with was to create a listen socket to hear that entering one, and it works just fine.

So, to avoid using 2 ports, Can we implement aditional functionality throught that port to be called from an external program?

Well you can’t connect because UE4 use UDP protocol (not TCP), which does not formally connect to server just throws packets at destination, in fact there no concept of client and server on UDP layer it’s just packet throwing and forget. This also means that it is packet loss tolerable unlike TCP and there no guaranty that packet will reach destination, while TCP monitors that and makes sure that packet lands even if this means large delay and waiting (or else internet really gonna cut off and connection gonna timeout). So if you want 100% sure that your data reach the server you should use TCP socket instead.

But if you really want to then get packets from game server you cna od that in UNetConnection class more specifically UIpConnection:

…which you can process raw packets ReceivedRawPacket function and and you can be overrided from UNetDriver and UIpNetDriver

https://api.unrealengine.com/INT/API/Plugins/OnlineSubsystemUtils/UNetDriver/index.html

Which you can in engine.ini as demostratted here:

https://github.com/EpicGames/UnrealEngine/blob/811c1ce579564fa92ecc22d9b70cbe9c8a8e4b9a/Engine/Config/BaseEngine.ini#L832

UNetConnection is extension of UPlayer, which represents the player it self (lower then APlayerController) so each player has it’s own. Not sure if it’s gonna accept packets from forgain ports. YOu relaly need to explore engine source code here.

After trying for a while bit i end up with a solution. Thanks for the answer and links! Right now i have managed to use the same port for both services, running in parallel, and works fantastic

Could you, please, share it in general(some code pieces would be great)? Because i’m stuck with the same problem right now…

Hi Shalim,

Sadly i was working for a company and i do not longer have access to that code, however i remember that i found this video useful:

Hope it can help you.
-W