The code on that website runs using loops, so I modified it to work with love's structure instead. I'm pretty confident that the issue isn't with that, as I'm still able to run both the server on my computer and the client on my computer, and it works just as I had intended. The issue has to do with others trying to connect to the server. In all of the examples I've seen for lua-enet, including examples made in love, the address of the server is marked as "localhost:<port>". I don't see how this allows a client to connect to a server, wouldn't the external IP also need to be provided, at least to the client? I've tried replacing the localhost part with my external IP, and that results in an error when I try to launch the client.
The port I'm using is forwarded properly, and it's a UCP port, which is what I'm assuming ENet uses based on what I've read about it, though I could be totally wrong on that.
Here is the code I'm using for the server:
Code: Select all
require "enet"
function love.load()
host = enet.host_create "localhost:6789"
hostReceived = 0
end
function love.draw()
if hostReceived == 1 then
love.graphics.print("Got message: ", 5, 5)
end
end
function love.update(dt)
event = host:service(100)
if event and event.type == "receive" then
hostReceived = 1
event.peer:send(event.data)
end
end
Code: Select all
require "enet"
function love.load()
connected = false
messageReceived = false
host = enet.host_create()
server = host:connect("localhost:6789")
continue = true
end
function love.draw()
if connected == true then
love.graphics.print("Connected to", 5, 5)
end
if messageReceived == true then
love.graphics.print("Got message: ", 5, 10)
end
end
function love.update(dt)
if continue == true then
event = host:service(100)
if event then
if event.type == "connect" then
connected = true
event.peer:send("hello world")
elseif event.type == "receive" then
messageReceived = true
continue = false
server:disconnect()
host:flush()
end
end
end
end