Garry's Mod Wiki

net

The net library is one of a number of ways to send data between the client and server.

The major advantages of the net library are the large size limit (64kb/message) and the ability to send data backwards - from the client to the server.

Refer to Net Library Usage for a short introduction.

Methods

net.Broadcast()
Sends the currently built net message to all connected players. More information can be found in Net Library Usage.
number, number net.BytesLeft()
Returns the amount of data left to read in the current message in bytes. Does nothing when sending data.
number, number net.BytesWritten()
Returns the size of the current message in bytes. This will include 3 extra bytes used by the engine internally to send the data over the network.
net.Incoming( number length, Player client )
This is used internally - although you're able to use it you probably shouldn't. You may be looking for net.Receive. Function called by the engine to tell the lua state a message arrived.
Angle net.ReadAngle()
Reads an angle from the received net message. You must read information in same order as you write it.
number net.ReadBit()
Reads a bit from the received net message. You must read information in same order as you write it.
boolean net.ReadBool()
Reads a boolean from the received net message. You must read information in same order as you write it.
table net.ReadColor()
Reads a Color from the current net message. You must read information in same order as you write it.
string net.ReadData( number length )
Reads pure binary data from the message. You must read information in same order as you write it.
number net.ReadDouble()
Reads a double-precision number from the received net message. You must read information in same order as you write it.
Entity net.ReadEntity()
Reads an entity from the received net message. You should always check if the specified entity exists as it may have been removed and therefor NULL if it is outside of the players PVS or was already removed. You must read information in same order as you write it.
number net.ReadFloat()
Reads a floating point number from the received net message. You must read information in same order as you write it.
number net.ReadHeader()
This is used internally - although you're able to use it you probably shouldn't. Reads a word, basically unsigned short. This is used internally to read the "header" of the message which is an unsigned short which can be converted to the corresponding message name via util.NetworkIDToString.
number net.ReadInt( number bitCount )
Reads an integer from the received net message. You must read information in same order as you write it.
VMatrix net.ReadMatrix()
Reads a VMatrix from the received net message. You must read information in same order as you write it.
Vector net.ReadNormal()
Reads a normal vector from the net message. You must read information in same order as you write it.
string net.ReadString()
Reads a null terminated string from the net stream. The size of the string is 8 bits plus 8 bits for every ASCII character in the string. You must read information in same order as you write it.
table net.ReadTable()
Reads a table from the received net message. Sometimes when sending a table through the net library, the order of the keys may be switched. So be cautious when comparing (See Example 1).You must read information in same order as you write it. See net.WriteTable for extra info. You may get net.ReadType: Couldn't read type X during the execution of the function, the problem is that you are sending objects that cannot be serialized/sent over the network.
any net.ReadType( number typeID = net.ReadUInt(8) )
This is used internally - although you're able to use it you probably shouldn't. Used internally by net.ReadTable. Reads a value from the net message with the specified type, written by net.WriteType. You must read information in same order as you write it.
number net.ReadUInt( number numberOfBits )
Reads an unsigned integer with the specified number of bits from the received net message. You must read information in same order as you write it.
Vector net.ReadVector()
Reads a vector from the received net message. Vectors sent by this function are compressed, which may result in precision loss. See net.WriteVector for more information. You must read information in same order as you write it.
net.Receive( string messageName, function callback )
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!
net.Send( Player ply )
Sends the current message to the specified player, or to all players listed in the table.
net.SendOmit( Player ply )
Sends the current message to all except the specified, or to all except all players in the table.
net.SendPAS( Vector position )
Sends the message to all players that are in the same potentially audible set(PAS) as the position, or simply said, it adds all players that can potentially hear sounds from this position.
net.SendPVS( Vector position )
Sends the message to all players the position is in the PVS of or, more simply said, sends the message to players that can potentially see this position.
net.SendToServer()
Sends the current message to the server.
boolean net.Start( string messageName, boolean unreliable = false )
Begins a new net message. If another net message is already started and hasn't been sent yet, it will be discarded. Each net message has a length limit of 64KB!The message name must be pooled with util.AddNetworkString beforehand!Net messages will not reliably reach the client until the client's GM:InitPostEntity hook is called.
net.WriteAngle( Angle angle )
Writes an angle to the current net message.
net.WriteBit( boolean boolean )
Appends a boolean (as 1 or 0) to the current net message. Please note that the bit is written here from a boolean (true/false) but net.ReadBit returns a number.
net.WriteBool( boolean boolean )
Appends a boolean to the current net message. Alias of net.WriteBit
net.WriteColor( table Color )
Appends a Color to the current net message.
net.WriteData( string binaryData, number length )
Writes a chunk of binary data to the message.
net.WriteDouble( number double )
Appends a double-precision number to the current net message.
net.WriteEntity( Entity entity )
Appends an entity to the current net message.
net.WriteFloat( number float )
Appends a float (number with decimals) to the current net message.
net.WriteInt( number integer, number bitCount )
Appends an integer - a whole number - to the current net message. Can be read back with net.ReadInt on the receiving end. Use net.WriteUInt to send an unsigned number (that you know will never be negative). Use net.WriteFloat for a non-whole number (e.g. 2.25).
net.WriteMatrix( VMatrix matrix )
Writes a VMatrix to the current net message.
net.WriteNormal( Vector normal )
Writes a normalized/direction vector ( Vector with length of 1 ) to the net message. This function uses less bandwidth compared to net.WriteVector and will not send vectors with length of > 1 properly.
net.WriteString( string string )
Appends a string to the current net message. The size of the string is 8 bits plus 8 bits for every ASCII character in the string. The maximum allowed length of a single written string is 65533 characters.
net.WriteTable( table table )
Appends a table to the current net message. Adds 16 extra bits per key/value pair so you're better off writing each individual key/value as the exact type if possible. All net messages have a 64kb buffer. This function will not check or error when that buffer is overflown. You might want to consider using util.TableToJSON and util.Compress and send the resulting string in 60kb chunks, doing the opposite on the receiving end.
net.WriteType( any Data )
This is used internally - although you're able to use it you probably shouldn't. Used internally by net.WriteTable. Appends any type of value to the current net message. An additional 8-bit unsigned integer indicating the type will automatically be written to the packet before the value, in order to facilitate reading with net.ReadType. If you know the data type you are writing, use a function meant for that specific data type to reduce amount of data sent.
net.WriteUInt( number unsignedInteger, number numberOfBits )
Appends an unsigned integer with the specified number of bits to the current net message. Use net.WriteInt if you want to send negative and positive numbers. Use net.WriteFloat for a non-whole number (e.g. 2.25). Unsigned numbers do not support negative numbers.
net.WriteVector( Vector vector )
Appends a vector to the current net message. Vectors sent by this function are compressed, which may result in precision loss. XYZ components greater than 16384 or less than -16384 are irrecoverably altered (most significant bits are trimmed) and precision after the decimal point is low.

Page Links


Special Pages


Wikis

?

Render Time: 124ms

DB GetPage 26
Generate Html 3
SaveChanges (1) 81
Render Body 0
Render Sidebar 12