HolyLib Wiki

SendConnectionlessPacket

  number gameserver.SendConnectionlessPacket( bf_write bf, string ip, boolean useDNS, number socket = NS_SERVER )

Description

Sends out a connectionless packet to the target ip.
See HolyLib:ProcessConnectionlessPacket for examples.

It's expected that YOU already added the connectionless header, this was done to not have to copy the buffer.
bf:WriteLong(-1) -- Write this as the first thing. This is the CONNECTIONLESS_HEADER

Arguments

1bf_write bf
The buffer to send
2string ip
The target to send the packet to. Format ip:port
3boolean useDNS
If true it will try to resolve the IP
4number socket = NS_SERVER
The socket to use for sending the packet.

Returns

1number length
Returns the length of the sent data or -1 on failure

Example

Example on how to send a loopback packet
hook.Add("HolyLib:ProcessConnectionlessPacket", "LoopbackExample", function(bf, ip) if ip != "loopback" then return end print("We got our own packet: " .. bf:ReadString()) return true end) local bf = bitbuf.CreateWriteBuffer(64) bf:WriteLong(-1) bf:WriteString("Hello World") -- We use NS_CLIENT as a socket because then the packet is queued into the Server loopback queue. gameserver.SendConnectionlessPacket(bf, "loopback:" .. gameserver.GetUDPPort(), false, gameserver.NS_CLIENT)