Code: Select all
local server = host:connect("localhost:6789")
I tried to break this down and user servers and peers using a more practical love.update loop. It creates a 'server' and a 'client' on the same machine - in the same script. IN other words, this one script will send a message from one port to another.
Code: Select all
enet = require "enet"
-- scoping things 'global' for debugging purposes
enethost = nil
hostevent = nil
clientpeer = nil
function love.load(args)
-- establish host for receiving msg
enethost = enet.host_create("localhost:6750")
-- establish a connection to host on same PC
enetclient = enet.host_create()
clientpeer = enetclient:connect("localhost:6750") --! hard coded for debugging
end
function love.update(dt)
ServerListen()
ClientSend()
end
function love.draw()
end
function ServerListen()
hostevent = enethost:service(100)
if hostevent then
print("Server detected message type: " .. hostevent.type)
if hostevent.type == "connect" then
print(hostevent.peer, "connected.")
end
if hostevent.type == "receive" then
print("Received message: ", hostevent.data, hostevent.peer)
end
end
end
function ClientSend()
clientpeer:send("Hi")
end
It doesn't work. When I query the clientpeer.status it says "connecting" forever and ever. The Server is not accepting the connection. I'd like to make this work and then include it on the wiki if the community feels that is useful.