Lua enet woes.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
pedrosgali
Party member
Posts: 107
Joined: Wed Oct 15, 2014 5:00 pm
Location: Yorkshire, England

Lua enet woes.

Post by pedrosgali »

Hi all, I've been playing around with enet recently and everything seems to work fine over lan but how do I get it to work over the internet? Here's the code I've been using...

Code: Select all

-- server.lua
local enet = require "enet"
local host = enet.host_create("*:25995")
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
And the client

Code: Select all

-- client.lua
local enet = require "enet"
local host = enet.host_create()
local server = host:connect("the ip and port go here...")
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
You'll probably recognise this from the wiki as it is a direct copy. I have the remote machine running in a hypervisor on a friends machine and the port in question is forwarded and open but I cannot seem to get the client to connect at all.
Am I doing this right? In the server code I specify the ip as "*" which should check all open connections on port 25995 but I get nothing.
Any advice would be greatly appreciated.

Code: Select all

if not wearTheseGlasses() then
  chewing_on_trashcan = true
end
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Lua enet woes.

Post by ReFreezed »

The code seems to be the same as what I've used and it did work for me. Maybe a firewall is blocking the connection? I'm guessing there's something between the computers preventing the connection. Maybe try to connect to a machine without any hypervisor.

This should be all that's needed to connect:

Code: Select all

-- Server
host = enet.host_create("*:12345")

-- Client
host = enet.host_create()
host:connect("SERVER_IP:12345")
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 25 guests