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.

-- 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