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

2017-03-21 15:43:16
enet.peer:state

enet.peer:state Returns the state of the peer as a string.

2017-03-21 15:43:40
enet.event

enet.event Description An event is a table generated by

2017-03-21 15:43:11
enet.host:total received data

enet.host:total received data Returns the number of bytes that were received by the given host. Function Synopsis

2017-03-21 15:43:26
enet.host:connect

enet.host:connect Connects a host to a remote

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

enet.peer:ping Send a ping request to peer, updates

2017-03-21 15:43:35
enet.peer:connect id

enet.peer:connect id Returns the field ENetPeer::connectID that is assigned for each connection. Function Synopsis

2017-03-21 15:43:30
enet.host:get socket address

enet.host:get socket address Returns a string that describes the socket address of the given

2017-03-21 15:43:23
enet.peer:reset

enet.peer:reset Forcefully disconnects peer. The

2017-03-21 15:43:37
enet.host:service

enet.host:service Wait for events, send and receive any ready

2017-03-21 15:43:24