{{newin|[[0.9.0]]|090|type=module}}

{{notice|Official documentation for lua-enet is available [http://leafo.net/lua-enet/ here]. ENet's features are listed on its [http://enet.bespin.org/Features.html 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 ==
{| class="wikitable"
!Type
!Description
|-
|[[enet.host | host]]
|An ENet host for communicating with peers.
|-
|[[enet.peer | peer]]
|An ENet peer which data packets may be sent or received from.
|-
|[[enet.event | event]]
|A simple table containing information on an event.
|}

== Functions ==
{| class="wikitable"
!Function
!Description
|-
|-
|[[enet.host_create | host_create]]
|Returns a new host.
|-
|[[enet.linked_version| linked_version]]
|Returns the included ENet's version string.
|}

== Examples ==
'''server.lua'''
<source lang="Lua">
-- server.lua
local enet = 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
</source>

'''client.lua'''
<source lang="Lua">
-- client.lua
local enet = 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
</source>

== See Also ==
* [[parent::love]]
* [[socket]]
== Other Languages ==
{{i18n|lua-enet}}

[[Category:Libraries]]
{{#set:Description=Multiplayer networking module for games.}}
{{#set:LOVE Version=0.9.0}}
{{#set:Keyword=Networking}}