Garry's Mod Wiki


  net.WriteData( string binaryData, number length = #binaryData )


Writes a chunk of binary data to the message.


1 string binaryData
The binary data to be sent.
2 number length = #binaryData
The length of the binary data to be sent, in bytes.


Sends a message to the server without using WriteString.

You don't need to use net.WriteUInt if you only use this function once in the net message.
You can get the bytes amount by dividing the message length by 8. Like this:
local compressed_message = net.ReadData( len / 8 ) -- Converts the length from Bits to Bytes.
-- Client local message = "This is a cool message" local compressed_message = util.Compress( message ) local bytes_amount = #compressed_message net.Start( "SendMessage" ) net.WriteUInt( bytes_amount, 16 ) -- Writes the amount of bytes we have. Needed to read the data net.WriteData( compressed_message, bytes_amount ) -- Writes the datas net.SendToServer() -- Server util.AddNetworkString( "SendMessage" ) net.Receive( "SendMessage", function( len, ply ) local bytes_amount = net.ReadUInt( 16 ) -- Gets back the amount of bytes our data has local compressed_message = net.ReadData( bytes_amount ) -- Gets back our compressed message local message = util.Decompress( compressed_message ) -- Decompresses our message print( message ) end)
This is a cool message