Difference between revisions of "enet.peer:send"

m
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Met en fil d'attente, un paquet à émettre à un [[enet.peer (Français)|peer]] (pair).
+
Queues a packet to be sent to the [[enet.peer | peer]].
  
== Fonction ==
+
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 7: Line 7:
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|string (Français)|data|The contents of the packet, it must be a [[string]].}}
+
{{param|string|data|The contents of the packet, it must be a [[string]].}}
{{param|number (Français)|channel|The channel to send the packet on. Optional. Defaults to 0.}}
+
{{param|number|channel|The channel to send the packet on. Optional. Defaults to 0.}}
{{param|strin (Français)g|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.}}
+
{{param|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.}}
=== Retourne ===
+
=== Returns ===
Rien.
+
Nothing.
  
== Voir également ==
+
== Function ==
* [[parent::lua-enet (Français)]]
+
{{newin|[[12.0]]|120|type=variant}}
* [[enet.peer (Français)]]
+
=== Synopsis ===
* [[enet.peer:receive (Français)]]
+
<source lang="lua">
* [[enet.host (Français)]]
+
peer:send(pointer, size, channel, flag)
* [[enet.event (Français)]]
+
</source>
[[Category:Functions (Français)]]
+
=== Arguments ===
{{#set:Description=Met en fil d'attente, un paquet à émettre à un [[enet.peer (Français)|peer]] (pair).}}
+
{{param|light userdata|pointer|The contents of the packet.}}
{{#set:Since=000}}
+
{{param|number|size|The size of the memory starting at the pointer.}}
 +
{{param|number|channel|The channel to send the packet on. Optional. Defaults to 0.}}
 +
{{param|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 ==
 +
{{newin|[[12.0]]|120|type=variant}}
 +
=== Send a packet using [[Data]] instead of a [[String]] ===
 +
<source lang="lua">
 +
-- 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
 +
</source>
 +
<source lang="lua">
 +
-- 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
 +
</source>
  
== Autres langues ==
+
== See Also ==
 +
* [[parent::lua-enet]]
 +
* [[enet.peer]]
 +
* [[enet.peer:receive]]
 +
* [[enet.host]]
 +
* [[enet.event]]
 +
== Other Languages ==
 
{{i18n|enet.peer:send}}
 
{{i18n|enet.peer:send}}

Latest revision as of 13:10, 10 May 2023

Queues a packet to be sent to the peer.

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