Client to Server

From GMod Wiki

Jump to: navigation, search
Warning 64 severe.pngDatastream is being removed from garrysmod once the GMod Beta 13 update becomes public


Lua: Datastream : Client to Server
Page white text.png Description:This is explains how to use datastream to send data to the server from the client.
link=User:Yoft Original Author:Yoft
Group.png Contributors:The community
Calendar.png Created:March 8, 2009
DescriptionSends data to the server.
Used onNewerClient.png
Code
require("datastream")
datastream.StreamToServer( "ExampleStream", { "Hi, I'm a string!", 1 } )
OutputSends "Hi, I'm, a string!"(String) and 1(Number) to the server.


DescriptionReceive data from a client (This goes along with the previous example)
Used onNewerServer.png
Code
require("datastream")
function exampleStreamHandler( sender, handler, id, encoded, decoded )
  Msg("Datastream received:\n")
  Msg("Sender: "..sender:Nick().."\n") --Our sender's name.
  Msg("Handler: "..handler.."\n") --Stream's handler (AKA Stream name), in our case, 'ExampleStream'.
  Msg("Data 1: "..decoded[1].."\n") --The first entry in the 'decoded' table, which is "Hi, I'm a string!".
  Msg("Data 2: "..decoded[2].."\n") --The second entry in 'decoded' table, which is 1.
end
datastream.Hook( "ExampleStream", exampleStreamHandler )
OutputDatastream received:

Sender: (Sender's Name)

Handler: ExampleStream

Data 1: Hi, I'm a string.

Data 2: 1
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox