e-net: host not working with external IP adress on port forwarding
Posted: Fri Jun 14, 2019 10:31 am
Whenever I try to use my external IP adress to let people from outside connect to my small chat program example, I get the error:
Error
main.lua:20: attempt to index global 'host' (a nil value)
Traceback
main.lua:20: in function 'update'
[C]: in function 'xpcall'
-> I've tried looking for a solution and literally nothing worked that was about the topic of letting other people connect with my external IP into my network.
Everything else works just fine. Using my IPV4 builds a connection, localhost builds a connection, using a star will only let my IPV4 connect and even using my Hamachi IP works just fine with other people.
Summary:
-> Yes, I have port forwarded 11000
-> connecting locally works fine.
-> External IP crashes the server
Code:
main.lua Server:
main.lua Client:
Thanks in advance for any help!
Error
main.lua:20: attempt to index global 'host' (a nil value)
Traceback
main.lua:20: in function 'update'
[C]: in function 'xpcall'
-> I've tried looking for a solution and literally nothing worked that was about the topic of letting other people connect with my external IP into my network.
Everything else works just fine. Using my IPV4 builds a connection, localhost builds a connection, using a star will only let my IPV4 connect and even using my Hamachi IP works just fine with other people.
Summary:
-> Yes, I have port forwarded 11000
-> connecting locally works fine.
-> External IP crashes the server
Code:
main.lua Server:
Code: Select all
function love.load()
require "serverFunctions"
enet = require "enet"
host = enet.host_create"(My external IP goes here):11000"
clients = {}
end
function love.update(dt)
event = host:service(0)
while event do
if event.type == "receive" then
print("Someone sent a message: ", event.data, event.peer)
sendToAllClients(event.data)
end
connectionHandler()
event = host:service()
end
end
-- Outside of main --
function split(s, delimiter)
result = {}
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end
function tablefind(tab,el)
for index, value in pairs(tab) do
if value == el then
return index
end
end
end
function connectionHandler()
if event.type == "connect" then
print(event.peer, "connected.")
table.insert(clients, event.peer)
for i,v in ipairs(clients) do
print("Client: " .. i .. " ", v)
end
end
if event.type == "disconnect" then
print(event.peer, " disconnected.")
table.remove(clients, tablefind(clients, event.peer))
for i,v in ipairs(clients) do
print("Client: " .. i .. " ", v)
end
end
end
function sendToAllClients(data)
for i = 1, #clients, 1 do
clients[i]:send(data)
end
end
main.lua Client:
Code: Select all
function love.load()
utf8 = require("utf8")
enet = require "enet"
host = enet.host_create()
server = host:connect("ExternalIP:11000")
done = false
stringpacket = "Nothing"
inputText = "Type here."
receiveText = "Nothing yet."
connected = false
end
function love.update()
event = host:service(100)
if event then
if event.type == "connect" then
print("Connected to", event.peer)
hostPeer = event.peer
connected = true
end
if event.type == "receive" then
receiveText = event.data
end
end
end
function love.keypressed(key)
if connected == true then
if key == "return" then
hostPeer:send(inputText)
inputText = ""
print("Text cleared")
end
if key == "s" then
hostPeer:disconnect()
end
end
if key == "backspace" then
byteoffset = utf8.offset(inputText, -1)
if byteoffset then
inputText = string.sub(inputText, 1, byteoffset - 1)
end
end
end
function love.textinput(input)
inputText = inputText .. input
end
function love.draw()
love.graphics.print(inputText, 10, 10, 0, 1)
love.graphics.print(receiveText, 10, 30, 0, 1)
end
-- Outside of main --
function split(s, delimiter)
result = {}
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end