Difference between revisions of "enet.host"

(Functions)
m (Autres langues)
 
(7 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
An ENet host for communicating with peers. On creation it will bind to a port on an address, unless otherwise specified, which will keep other applications from binding to the same port and address.
 
An ENet host for communicating with peers. On creation it will bind to a port on an address, unless otherwise specified, which will keep other applications from binding to the same port and address.
  
The only way to free the port is by garbage collecting the ENet host, which can be done like so:
+
One can free the port by calling its destroy method; nil-ing the host object and calling collectgarbage() would work as well, since :destroy calls host:__gc internally, but this is cleaner:
 
<source lang="Lua">
 
<source lang="Lua">
 
local host = enet.host_create("*:6789")
 
local host = enet.host_create("*:6789")
host = nil
+
host:destroy()
garbagecollect()
 
 
</source>
 
</source>
  
Line 19: Line 18:
 
|[[enet.host:check_events | host:check_events]]
 
|[[enet.host:check_events | host:check_events]]
 
|Checks for any queued [[enet.event | events]] and dispatches one if available.
 
|Checks for any queued [[enet.event | events]] and dispatches one if available.
 +
|-
 +
|[[enet.host:compress_with_range_coder | host:compress_with_range_coder]]
 +
|Toggles an adaptive order-2 PPM range coder for the transmitted data of all peers.
 
|-
 
|-
 
|[[enet.host:connect | host:connect]]
 
|[[enet.host:connect | host:connect]]
Line 35: Line 37:
 
|Sets the bandwidth limits of the host in bytes/sec.
 
|Sets the bandwidth limits of the host in bytes/sec.
 
|-
 
|-
|[[enet.host:socket_get_address | host:socket_get_address]]
+
|[[enet.host:get_socket_address | host:get_socket_address]]
 
|Returns a [[string]] that describes the socket address of the given host.
 
|Returns a [[string]] that describes the socket address of the given host.
 +
|-
 +
|[[enet.host:get_socket_address | host:socket_get_address]]
 +
|Deprecated version of host:get_socket_address.
 +
|-
 +
|[[enet.host:destroy | host:destroy]]
 +
|Destroys the host, freeing any bound ports and addresses. Alias for the host:__gc method.
 
|-
 
|-
 
|[[enet.host:total_sent_data | host:total_sent_data]]
 
|[[enet.host:total_sent_data | host:total_sent_data]]
Line 53: Line 61:
 
|Returns the connected [[enet.peer | peer]] at the specified index (starting at 1).
 
|Returns the connected [[enet.peer | peer]] at the specified index (starting at 1).
 
|-
 
|-
|[[enet.host:__gc | host:__gc]]
+
|[[enet.host:destroy | host:__gc]]
 
|Destroys the host, freeing any bound ports and addresses.
 
|Destroys the host, freeing any bound ports and addresses.
 
|}
 
|}
Line 59: Line 67:
 
== See Also ==
 
== See Also ==
 
* [[parent::lua-enet]]
 
* [[parent::lua-enet]]
 +
* [[enet:host_create]]
 
* [[enet.event]]
 
* [[enet.event]]
 
* [[enet.peer]]
 
* [[enet.peer]]
 +
 +
== Other Languages ==
 +
{{i18n|enet.host}}

Latest revision as of 09:35, 23 June 2023

Description

An ENet host for communicating with peers. On creation it will bind to a port on an address, unless otherwise specified, which will keep other applications from binding to the same port and address.

One can free the port by calling its destroy method; nil-ing the host object and calling collectgarbage() would work as well, since :destroy calls host:__gc internally, but this is cleaner:

local host = enet.host_create("*:6789")
host:destroy()

Functions

Function Description
host:service Wait for events, send and receive any ready packets.
host:check_events Checks for any queued events and dispatches one if available.
host:compress_with_range_coder Toggles an adaptive order-2 PPM range coder for the transmitted data of all peers.
host:connect Connects a host to a remote host. Returns peer object associated with remote host.
host:flush Sends any queued packets.
host:broadcast Queues a packet to be sent to all connected peers.
host:channel_limit Sets the maximum number of channels allowed.
host:bandwidth_limit Sets the bandwidth limits of the host in bytes/sec.
host:get_socket_address Returns a string that describes the socket address of the given host.
host:socket_get_address Deprecated version of host:get_socket_address.
host:destroy Destroys the host, freeing any bound ports and addresses. Alias for the host:__gc method.
host:total_sent_data Returns the number of bytes that were sent through the given host.
host:total_received_data Returns the number of bytes that were received by the given host.
host:service_time Returns the timestamp of the last call to host:service() or host:flush().
host:peer_count Returns the number of peers that are allocated for the given host.
host:get_peer Returns the connected peer at the specified index (starting at 1).
host:__gc Destroys the host, freeing any bound ports and addresses.

See Also

Other Languages