Garry's Mod Wiki

Revision Difference

net.Start#561312

<function name="Start" parent="net" type="libraryfunc"> <description>Begins a new net message. If another net message is already started and hasn't been sent yet, it will be discarded. ⤶ <warning>Each net message has a length limit of 65,533 bytes (approximately 64 KiB) and your net message will error and fail to send if it is larger than this.⤶ ⤶ After calling this function, you will want to call `net.Write` functions to write your data, if any, and then finish with a call to one of the following functions:⤶ * <page>net.Send</page>⤶ * <page>net.SendOmit</page>⤶ * <page>net.SendPAS</page>⤶ * <page>net.SendPVS</page>⤶ * <page>net.Broadcast</page>⤶ * <page>net.SendToServer</page>⤶ ⤶ ⤶ <warning>Each net message has a length limit of 65,533 bytes (approximately 64 KiB) and your net message will error and fail to send if it is larger than this.⤶ The net library has an internal buffer that sent messages are added to that is capable of holding roughly 256 kb at a time. Trying to send more will lead to the client being kicked because of a buffer overflow. <page text="More information on net library limits can be found here.">Networking_Usage#netlimits</page> The message name must be pooled with <page>util.AddNetworkString</page> beforehand! Net messages will not reliably reach the client until the client's <page>GM:InitPostEntity</page> hook is called.</warning> </description> <realm>Shared</realm> <args> <arg name="messageName" type="string">The name of the message to send</arg> <arg name="unreliable" type="boolean" default="false">If set to `true`, the message is not guaranteed to reach its destination</arg> </args> <rets> <ret name="" type="boolean">`true` if the message has been started.</ret> </rets> </function> <example> <description>Adds a console command that sends a message to all clients.</description> <code> if ( SERVER ) then util.AddNetworkString( "my_message" ) concommand.Add( "send_msg", function( ply, cmd, args, str ) if ( str == "" ) then str = "No message given" end net.Start( "my_message" ) net.WriteString( str ) net.WriteColor( ply:GetColor(), false ) net.Broadcast() end ) else net.Receive( "my_message", function( len, ply ) -- Important: reading in the same order as we write! local message = net.ReadString() local color = net.ReadColor( false ) print( "Message from server received." ) MsgC( color, message ) end ) end </code> </example>