Send data to client from server.

I’m curious if there is an easy way to send information from the server to the client for processing. I’ve been trying to replicate a large array that is around 150kb of data, but it really is messing up my replication (actors not replicating correctly, clients not spawning blueprints correctly).

I’d like to set something like this up:
diagram.png

So the client makes a request to the server and the server sends that data from the database back to the client. The client then processes this locally and displays the content. This can all happen asynchronously while the game is still running.

If you have a replicated array, you can “ask the server” to update it with a “server method”, UFUNCTION(Server,…), the server queries the DB in a background thread (extending FRunnable for example), modifies the array and then the client can be notified of the elements of the array that have changed if you configure it using UPROPERTY(ReplicatedUsing=…). If the client needs to act on the world, you’ll probably need then to perform the updates in the Game thread (using TGraphTask<FMyUpdateTask>::CreateTask(…) for example).

It’s not simple and straight, but it can be done ;). We do similar things to notify the DB* of events that have to be persisted and/or query the DB* for information that we need (persistent data for the current user etc.)

HIH, cheers

D.

PD: Not exactly the DB but the backend server.

My problem with replicating the array is that the amount of data it is replicating is really messing up my game (I believe this is documented in the Dynamic Array replication article). I guess I could have the server store a string and replicate the string to the client, unserialize it and then process the data that way, but I think since the amount of data is “large” (over the size of a standard type like int32, float, FVector, etc), the replication just go crazy because there is so much data to replicate.

If I could replicate a small value and have that trigger an OnRep to pull from the server like in the image above, I’d like to be able to accomplish that. Your FRunnable suggestion will be good on the server side, but from the server to the client I’m still at a loss how to do this without replication.

In UE3, I’ve seen some suggestions about using a client<->server round robin mechanism using reliable RPC to pass “big data” in chunks in order not to go over the network limit, but we have not had such an issue so far with UE4, so I’m not sure if the same limitations, and solutions apply.

How large is the data? Would it be more effective to serve the data separately and have both the client and the server utilize it remotely? For instance, set up a MySQL server with a web service to interface it, then have both the server and the client communicate with the DB service.

VegasRich - That is what I was thinking, but what happens on a game hosted by one client consumed by other clients? Someone would have to make sure their MySQL instance is running and that it is accessible by all clients. With going through the authority client, this would ensure that the data would be available if hosted by a MySQL server or a local sqlite file.

This is from ages ago but if you’re here from Google, I wrote a component that makes this really easy called UTransferComponent. It chunks up the data into pieces that can be sent in an RPC call and sends as many chunks per tick as it can while not overflowing the outgoing reliable buffer. It’s bidirectional so you can use SendBufferToServer or SendBufferToClient and then retrieve the data on that side.
This is a gist with the code for it:

And a video on how to use it: