Page 1 of 1

Lua-enet, Which Ip to put in.

Posted: Thu Oct 08, 2015 1:34 am
by Sharkinmytea
Hi I made a recent post about how when I dragged the window my server crashed up until now, I've been working with this address :
'localhost:17771'
I forwarded the port 17771 on my router for the the ip range of 192.168.0.100 to 192.168.0.110.
Know I want to play with my friends and I know they cant use this ip, so how do I determine which ip i have to put in there so taht they can join me.

Also if the code helps Here's the server:

Code: Select all

require('enet')
sentdata = 0
recieveddata = 0
count = 2
local  host = enet.host_create('IP ADDRESS:17771')

function love.update(dt) 

local event = host:service(100)
	if event then 
		if event.type == "receive" then
			print("Got message: ",  event.data, event.peer)
			recieveddata = event.data
		elseif event.type == "connect" then
		else
			print("Got event", event.type, event.peer)
		end
	end
host:broadcast(sentdata)
end

function love.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.print('Recieved Data: '..recieveddata..'     Data To Be Sent: '..sentdata,100,100)
end
And here's the client:

Code: Select all

require('enet')
require('socket')
count = 0
local host = enet.host_create()
local server = host:connect('woops:17771')
stillonline = ""
flushcounter = 0
function love.update(dt)
myip = socket.dns.toip(socket.dns.gethostname()) 

 event = host:service(50)

flushcounte = flushcounter + 1

s = socket.udp()
s:setpeername("74.125.115.104",80)
ip, _ = s:getsockname()

	if event then
		if event.type == "receive" then
			print("Got message: ",  event.data)
		elseif event.type == "disconnect" then
			stillonline = event.type
		elseif event.type == "connect" then
		stillonline = event.type
		end
	end

if flushcounter > 50 then -- Flush each (50*dt seconds)
host:flush()
end
count = count + 100
host:broadcast(count)
end
function love.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.print( 'Count:   '..count.."                    DEAD DATA".."\n"..stillonline.."\n".."Dns.toip :"..myip.."\n".."Local IP :"..ip,100,100)
end

Re: Lua-enet, Which Ip to put in.

Posted: Thu Oct 08, 2015 1:59 am
by Beelz
If you setup your router to give your computer's MAC address a static IP, you'll only need to forward the port for that IP. If you don't know how to do that I would just open the port for the entire range: 192.168.0.0 - 192.168.0.255
You may be having issues by just having the wrong IP.

For others to connect they should just use your external IP address... Speaking of which you shouldn't post your IP on public forums, just saying. If you are planning to have one exclusive server for the game I would hide the server's IP address somewhere in a required file or something.

Re: Lua-enet, Which Ip to put in.

Posted: Thu Oct 08, 2015 2:06 am
by Sharkinmytea
Well i tried searching :external address ip on google and it gave me an IP.
I tried to use that, but each time I use an IP that isnt local (0.0.0.0 / localhost / 192.168.0.101) it gives me the error:
main.lua:9 attempt to index upvalue 'host' (a nil value)
Only on the server

The client, I assume, keeps searching for the server on that IP until it connects...

Re: Lua-enet, Which Ip to put in.

Posted: Thu Oct 08, 2015 2:34 am
by Beelz
Honestly I've never used eNet so I'm not familiar with its implementation. Looking into the documentation I see:

Code: Select all

int enet_host_service	( ENetHost * 	 host,
                          ENetEvent *    event,
                          enet_uint32    timeout 
                        )
You seem to be missing a required variable

Code: Select all

local event = host:service(100)
------------------
EDIT

I also notice in your code you are changing the function names... Like you use "host_create" but also "host:service". If create works but not service I would try "host_service" and see where you get.

Re: Lua-enet, Which Ip to put in.

Posted: Thu Oct 08, 2015 2:39 am
by Sharkinmytea
Well, I dont know much about what you posted but i'm pretty sure i gave all the arguments I could.
Here is the reference I used for this function
http://leafo.net/lua-enet/#hostservicetimeout

The host is determined in the start of the file, it has the IP and port.
The event is returned when the function is called and the timeout is written in the argument section of the function.

Re: Lua-enet, Which Ip to put in.

Posted: Thu Oct 08, 2015 2:55 am
by Beelz
I see... I was thinking, I'm not sure this will even work with Love2d because you would need to put a "while true" loop in the update function to keep the server listening, freezing up the rest of the program.

Re: Lua-enet, Which Ip to put in.

Posted: Thu Oct 08, 2015 3:06 am
by Sharkinmytea
lllllllllllll

Re: Lua-enet, Which Ip to put in.

Posted: Thu Oct 08, 2015 3:19 am
by Beelz
But being in the update function means you are trying to restart the server every update... That's probably why it isn't working.

To find your internal IP open the start menu and type "cmd.exe". When that opens type "ipconfig". Your internal IP is the IPv4 Address.