Revision Difference
net.WriteData#546569
<function name="WriteData" parent="net" type="libraryfunc">
<description>Writes a chunk of binary data to the message.</description>
<realm>Shared</realm>
<args>
<arg name="binaryData" type="string">The binary data to be sent.</arg>
<arg name="length" type="number" default="#binaryData">The length of the binary data to be sent, in bytes.</arg>
</args>
</function>
⤶
⤶
<example>⤶
<description>Sends a message to the server without using WriteString</description>⤶
⤶
<example>⤶
<description>Sends a message to the server without using WriteString.</description>⤶
<code>
-- 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.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 )
⤶
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)
end)
</code>
<output>"This is a cool message"</output>⤶
<output>⤶
```⤶
This is a cool message⤶
```⤶
</output>⤶
</example>