enet.host

enet.host 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

enet.host create

enet.host create Returns a new host. All arguments are optional. A bind_address of nil makes a host that can not be connected to (typically a client). Otherwise the address can either be of the form <ipaddress>:<port>, <hostname>:<port>, or *:<port>. Example addresses include "127.0.0.1:8888", "localhost:2232", and "*:6767". Function Synopsis host = enet.host_create(bind_address, peer_count, channel_count, in_bandwidth, out_bandwidth) Arguments string bind_add

enet.host:bandwidth limit

enet.host:bandwidth limit Sets the bandwidth limits of the host in bytes/sec. Set to 0 for unlimited. Function Synopsis host:bandwidth_limit(incoming, outgoing) Arguments number incoming Download speed limit in bytes/sec. number outgoing Upload speed limit in bytes/sec. Returns Nothing. See Also lua-enet enet.host

enet.host:broadcast

enet.host:broadcast Queues a packet to be sent to all connected peers. Function Synopsis host:broadcast(data, channel, flag) Arguments string data The data to send. number channel The channel to send the packet on. 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. U

enet.host:channel limit

enet.host:channel limit Sets the maximum number of channels allowed. If it is 0 then the system maximum allowable value is used. Function Synopsis host:channel_limit(limit) Arguments number limit The maximum number of channels allowed. Returns Nothing. See Also lua-enet enet.host

enet.host:check events

enet.host:check events Checks for any queued events and dispatches one if available. Returns the associated event if something was dispatched, otherwise nil. Function Synopsis event = host:check_events() Arguments None. Returns table event An event or nil if no events are available. See Also lua-enet enet.event enet.host:service

enet.host:compress with range coder

enet.host:compress with range coder Toggles an adaptive order-2 PPM range coder for the transmitted data of all peers. Function Synopsis host:compress_with_range_coder() Arguments None. Returns boolean state True if the compression algorithm is active, false if not. See Also lua-enet enet.host

enet.host:connect

enet.host:connect Connects a host to a remote host. Returns peer object associated with the remote host. The actual connection will not take place until the next host:service() is called, in which a "connect" event will be generated. Function Synopsis peer = host:connect(address, channel_count, data) Arguments string address The address to connect to in the format "ip:port". number channel_count The number of channels to allocate. It should be the same as the channel count on the serve

enet.host:destroy

enet.host:destroy Destroys the host structure and closes all of its connections. This function is also ran automatically by lua's garbage collector, since it's an alias to host:__gc. Function Synopsis host:destroy() Arguments None. Returns Nothing. See Also lua-enet enet.host

enet.host:flush

enet.host:flush Sends any queued packets. This is only required to send packets earlier than the next call to host:service, or if host:service will not be called again. Function Synopsis host:flush() Arguments None. Returns Nothing. See Also lua-enet enet.host:service enet.host