What is the best method for client->server communication?

Alright so basically I have a very complicated stat system. On the client, each player has an array of lots of variables. To sum up the server->client communicated, there are clientside and serverside functions that use User Messages to communicate with each other. So the server requests a value and the client send the data to the server. Now that’s easy, but with User Messages I can only achieve setting of values on the client from the server, but I can’t actually get a value from the client. I was wondering if people could discuss and suggest a few methods that would work for me. I was thinking that essentially I need to execute a function on the server that requests data from the client, which can be done via User Messages of course. Then that will run a function on the client which will then send data to the server, and in the same function that requested data from the client will pick up the data sent from the client. The theory is good, but two problems. There is no guarantee that the client will report back by the time the server checks for data, and I don’t know how to send data from the client to the server in the first place.


Use the net library.

Does the server delete the received data from memory when it’s done using it, or does it stay there for a while?

[editline]23rd February 2014[/editline]

Also, I’m trying to think this out and I don’t think net is my solution. Let me explain more. So somewhere on the server I run a function which needs to return data from the client. I don’t want to run a function on the server from the client. For example I have GetMaxWhatever on the server. And I need to get a value from the client when this is executed on the server. Obviously I can do this by player, but still.

You need to be more specific with what you’re doing.

Could you use network vars?
(which is the net library)

What value are you trying to get from the client? Make sure you auth the input - never trust the client.

Could you possible give me a quick example?

Use the net library, here’s the logic behind it.

Server Needs Info -> Broadcast net message to clients.
Clients receive message -> Send back a message to the server.
Server receives said message -> Store into variable/table.