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:check events

enet.host:check events Checks for any queued events and dispatches one if available. Returns the associated

2017-03-21 15:43:17
enet.host:get peer

enet.host:get peer Returns the connected peer at the specified

2017-03-21 15:43:22
enet.peer:disconnect

enet.peer:disconnect Requests a disconnection from the peer

2017-03-21 15:43:31
enet.linked version

enet.linked version Returns the included ENet's version as a string. Function Synopsis

2017-03-21 15:43:28
enet.host:peer count

enet.host:peer count Returns the number of peers that are allocated

2017-03-21 15:43:23
enet.peer:disconnect now

enet.peer:disconnect now Force immediate disconnection from peer

2017-03-21 15:43:32
enet.host:service time

enet.host:service time Returns the time-stamp of the last call to

2017-03-21 15:43:25
enet.peer:round trip time

enet.peer:round trip time Returns or sets the current round trip time (i.e. ping). If value is nil the current value of the

2017-03-21 15:43:38
enet.host create

enet.host create Returns a new host. All arguments are optional

2017-03-21 15:43:14
enet.peer:disconnect later

enet.peer:disconnect later Request a disconnection from peer

2017-03-21 15:43:31