Garry's Mod Wiki

net.Receive

net.Receive( string messageName, function callback )

Description

Adds a net message handler. Only one receiver can be used to receive the net message.

The message-name is converted to lower-case so the message-names "BigBlue" and "bigblue" would be equal.
You must put this function outside of any other function or hook for it to work properly unless you know what you are doing!
You must read information in the same order as you write it.
Each net message has a length limit of 64KB!

Arguments

1 string messageName
The message name to hook to.
2 function callback
The function to be called if the specified message was received. Arguments are:

number len - Length of the message, in bits Player ply - The player that sent the message, works only serverside

Example

A simple callback

net.Receive( "my_message", function( len, pl ) if ( IsValid( pl ) and pl:IsPlayer() ) then print( "Message from " .. pl:Nick() .. " received. Its length is " .. len .. "." ) else print( "Message from server received. Its length is " .. len .. "." ) end end )
Output: When run server-side:

Message from John received. Its length is 4.

And client-side:

Message from server received. Its length is 4.

Page Links


Special Pages


Wikis

?

Render Time: 43ms

Session 0
DB GetPage 4
Generate Html 8
SaveChanges 16
Render Body 0
Render Sidebar 6