Download

Send TCP Notification to UE4 Client

I have written custom server code to manage logins, friends and notifications. I am currently accessing the data in UE4 using HTTP requests and that works just great.

However, I need the server to notify the client when certain things happen (ie. Group invite, friend request, etc). My original intention was for the client to just check every x seconds but that solution is not scalable, it’s slow, and is essentially a “friendly DDOS” when enough players are playing.

I have created a simple TCP listener on 127.0.0.1 and have successfully connected on telnet from my local machine. However, I have no idea how to connect sockets from outside my network given my public IP, port and whatever else is needed. The UE4 client submits it’s public IP address upon login but simply trying to connect to that public IP/port obviously isn’t working. I’m sure it would work with manual port forwarding but I need it to work on mobile as well.

I am relatively inexperienced in the world of sockets so please bare with me.

Here is my TCP Listener Initialization / Callback:


void UHDNotiWidget::StartNotificationChecks() {

    // listening socket
    FIPv4Address Addr;
    FIPv4Address::Parse("127.0.0.1", Addr);
    FIPv4Endpoint Endpoint(Addr, 41069);

    FSocket* ListenerSocket = FTcpSocketBuilder("NotificationListeningSocket")
        .AsReusable()
        .BoundToEndpoint(Endpoint)
        .Listening(8);

    //Set Buffer Size
    int32 ReceiveBufferSize = 2 * 1024 * 1024;
    int32 NewSize = 0;
    ListenerSocket->SetReceiveBufferSize(ReceiveBufferSize, NewSize);

    FTcpListener* NotificationListener = new FTcpListener(*ListenerSocket);
    NotificationListener->OnConnectionAccepted().BindUObject(this, &UHDNotiWidget::NotificationReceived);

    if (NotificationListener->Init()) {
        GEngine->AddOnScreenDebugMessage(-1, 60.f, FColor::Red, "TCP Listener Started");
    }
    else {
        GEngine->AddOnScreenDebugMessage(-1, 60.f, FColor::Red, "TCP Listener Failed To Start");
    }


}

bool UHDNotiWidget::NotificationReceived(FSocket* InSocket, const FIPv4Endpoint& ClientEndPoint) {
    GEngine->AddOnScreenDebugMessage(-1, 60.f, FColor::Red, "TCP Notification Received!");

    return true;
}

This works wonderfully locally but I have no idea how to reach it from outside my local network/machine.

Is it a matter of setting the correct Endpoint on the client socket (instead of 127.0.0.1)? I read some people using the Steam subsystem to help route sockets but that is Windows-exclusive I believe? I spent all of last night trying to figure out exactly what the process might look like but I don’t know the jargon well enough to ask Google the right questions.

My game is intended to be multi-platform and work on Android, iOS, Windows. It will primarily be a mobile app so its critical that I can reliably reach the UE4 client on the phone while connected to 4G.

Thank you so much in advance! I am more than happy to clarify anything that I didn’t explain well enough.