lua-enet

Available since LÖVE 0.9.0
This module is not supported in earlier versions.


Official documentation for lua-enet is available here. ENet's features are listed on its homepage. The official documentation may have typos. The documentation on this wiki reflects Löve's implementation, meaning it should be safe to follow what's written here.

lua-enet is simply some Lua bindings for ENet.

ENet's purpose is to provide a relatively thin, simple and robust network communication layer for games on top of UDP (User Datagram Protocol).The primary feature it provides is optional reliable, in-order delivery of packets.

ENet omits certain higher level networking features such as authentication, lobbying, server discovery, encryption, or other similar tasks that are particularly application specific so that the library remains flexible, portable, and easily embeddable.

Types

Type Description
host An ENet host for communicating with peers.
peer An ENet peer which data packets may be sent or received from.
event A simple table containing information on an event.

Functions

Function Description
host_create Returns a new host.
linked_version Returns the included ENet's version string.

Examples

server.lua

-- server.lua
require "enet"
local host = enet.host_create("localhost:6789")
while true do
  local event = host:service(100)
  while event do
    if event.type == "receive" then
      print("Got message: ", event.data, event.peer)
      event.peer:send( "pong" )
    elseif event.type == "connect" then
      print(event.peer, "connected.")
    elseif event.type == "disconnect" then
      print(event.peer, "disconnected.")
    end
    event = host:service()
  end
end

client.lua

-- client.lua
require "enet"
local host = enet.host_create()
local server = host:connect("localhost:6789")
while true do
  local event = host:service(100)
  while event do
    if event.type == "receive" then
      print("Got message: ", event.data, event.peer)
      event.peer:send( "ping" )
    elseif event.type == "connect" then
      print(event.peer, "connected.")
      event.peer:send( "ping" )
    elseif event.type == "disconnect" then
      print(event.peer, "disconnected.")
    end
    event = host:service()
  end
end

See Also


enet.peer:send

enet.peer:send Queues a packet to be sent to the peer.

2017-03-21 15:43:39
enet.peer:ping interval

enet.peer:ping interval Specifies the interval in milliseconds that pings are sent to the other end of the connection (defaults to 500). Function

2017-03-21 15:43:36
enet.host:bandwidth limit

enet.host:bandwidth limit Sets the bandwidth limits of the host

2017-03-21 15:43:14
enet.peer:throttle configure

enet.peer:throttle configure Changes the probability at which unreliable packets should not be dropped. Function Synopsis

2017-03-21 15:43:41
enet.peer:receive

enet.peer:receive Attempts to dequeue an incoming packet for this

2017-03-21 15:43:36
enet.host:destroy

enet.host:destroy Destroys the host structure and closes all

2017-03-21 15:43:19
enet.peer:index

enet.peer:index Returns the index of the peer. All

2017-03-21 15:43:33
enet.host:broadcast

enet.host:broadcast Queues a packet to be sent to all connected

2017-03-21 15:43:15
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

2017-03-21 15:43:13
enet.host:compress with range coder

enet.host:compress with range coder Toggles an adaptive order-2 PPM

2017-03-21 15:43:18