How to send data from client to server

What’s the best way to do it?


That’s the only way to do it.


Generally, console commands are the cleanest, securest, and most efficient way of doing it. i.e.

[lua]concommand.Add(“print_data”,function(pl,cmd,args) print(args[1]) end)[/lua]

] print_data Hello!

Where “Hello” is printed on the server.

An alternative way, which is primarily used to transfer large amounts of data like tables is datastream. Datastream is also nice in that whereas with concommands you can only send strings as arguments, datastream can stream any sort of GLON-encodable object (so most everything you’d want to send).

[lua]if CLIENT then

local t = { ["key"] = "value", f = "x" };
datastream.StreamToServer( "MyDatastream", t );


if SERVER then

datastream.Hook( "MyDatastream", function( pl, handler, id, enc, decoded )
	if type(decoded) == "table" then 


Datastream use’s concommands.

Concommands and GLON, right?

I mean, if you get technical, yes, but just trying to provide a basic explanation for those not familiar with the concept.

Why can’t you just loop through the table and send piece of each data to store server side? Datastream isn’t needed at all.

Datastream does that, its for lazehs.

Your Way
Step 1. Make the concommand that recieves the args and such
Step 2. Set up the for loop that runs the concommand
Step 3. Serialize all data with GLON, and run the for loop
Step 4. ignore the fact that your concommand is just a concommand, and doesn’t have a nice hooking system like datastream

With Datastream
Step 1. Call the function clientside.
Step 2. Hook it serverside.

Datastream GLON encodes the data (this usually takes 0.2 - 2 seconds), when sometimes it doesn’t have to be encoded.

Datastream is only necessary if you’re sending huge huge huge tables.

I use datastream for my admin mod plugin’s system and have seen no problem with it apart from that it brakes from time to time ^^ personally, i would use datastream just because its easier in this case but dont use it to often though :slight_smile:

I used to only use datastreams for client-to-server, but I noticed that there often is a noticeable delay up to a second when the script is juggling large amounts of data with datastream; so yeah, using concommands, et is just the better then datastreaming. Datastreaming, it is just not so good as the console commands.

Stealing is easier, but you wouldn’t would you?

Datastream is indeed whoppingly inefficient.