Difference between revisions of "enet.peer:send"
(Added variant added in love 12) |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 29: | Line 29: | ||
== Examples == | == Examples == | ||
{{newin|[[12.0]]|120|type=variant}} | {{newin|[[12.0]]|120|type=variant}} | ||
− | === Send a packet using [[Data]] instead of a | + | === Send a packet using [[Data]] instead of a [[String]] === |
<source lang="lua"> | <source lang="lua"> | ||
-- client | -- client | ||
local enet = require("enet") | local enet = require("enet") | ||
local host = enet.host_create() | local host = enet.host_create() | ||
− | local server = host:connect("localhost:10001" | + | local server = host:connect("localhost:10001", 0) |
host:service(100) | host:service(100) | ||
Latest revision as of 13:10, 10 May 2023
Queues a packet to be sent to the peer.
Contents
Function
Synopsis
peer:send(data, channel, flag)
Arguments
string data
- The contents of the packet, it must be a string.
number channel
- The channel to send the packet on. Optional. Defaults to 0.
string flag
- flag is one of "reliable", "unsequenced", or "unreliable". Reliable packets are guaranteed to arrive, and arrive in the order in which they are sent. Unreliable packets arrive in the order in which they are sent, but they aren't guaranteed to arrive. Unsequenced packets are neither guaranteed to arrive, nor do they have any guarantee on the order they arrive. Optional. Defaults to reliable.
Returns
Nothing.
Function
Available since LÖVE 12.0 |
This variant is not supported in earlier versions. |
Synopsis
peer:send(pointer, size, channel, flag)
Arguments
light userdata pointer
- The contents of the packet.
number size
- The size of the memory starting at the pointer.
number channel
- The channel to send the packet on. Optional. Defaults to 0.
string flag
- flag is one of "reliable", "unsequenced", or "unreliable". Reliable packets are guaranteed to arrive, and arrive in the order in which they are sent. Unreliable packets arrive in the order in which they are sent, but they aren't guaranteed to arrive. Unsequenced packets are neither guaranteed to arrive, nor do they have any guarantee on the order they arrive. Optional. Defaults to reliable.
Returns
Nothing.
Examples
Available since LÖVE 12.0 |
This variant is not supported in earlier versions. |
Send a packet using Data instead of a String
-- client
local enet = require("enet")
local host = enet.host_create()
local server = host:connect("localhost:10001", 0)
host:service(100)
-- populate byteData
local byteData = love.data.newByteData(5)
local ffi = require("ffi")
local ptr = ffi.cast("void*", byteData:getFFIPointer())
ffi.copy(ptr, "hello")
server:send(byteData:getPointer(), byteData:getSize(), 11, "reliable") -- send data
love.update = function()
host:service(10)
end
-- server
local enet = require("enet")
local host = enet.host_create("*:10001", 64, 0)
local text, channel
love.update = function()
local event = host:service(10)
if event and event.type == "receive" then
text = event.data
channel = event.channel
end
end
love.draw = function()
-- prints 'hello' once client joins and the channel it was sent on
love.graphics.print(tostring(text).."\nChannel: "..tostring(channel))
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info