Page 21 of 34

Re: LUBE (Networking Library)

Posted: Wed May 19, 2010 8:56 pm
by bartbes
When you have connected you can use lube.server/client.socket:getsockname() to get your local ip and port.
If you need your external IP you should look at something like STUN or some other form of UDP hole punching. You could also try to find a site like whatismyip.com and parse it's return data (check out http://www.whatismyip.com/automation/n09230945.asp).

EDIT: Do note that the last method doesn't give you a port, so there's no way of knowing you can actually reach the host behind the NAT.

Re: LUBE (Networking Library)

Posted: Sat May 29, 2010 2:55 pm
by thelinx
Hey.
Hey.

Re-upload it.

Re: LUBE (Networking Library)

Posted: Sat May 29, 2010 3:01 pm
by bartbes
Easy dude, easy, I'm releasing a new version.. soon.

Re: LUBE (Networking Library)

Posted: Sun May 30, 2010 12:32 pm
by Chief
bartbes wrote:Easy dude, easy, I'm releasing a new version.. soon.
...GIEF.

Re: LUBE (Networking Library)

Posted: Mon May 31, 2010 3:47 pm
by bartbes
Forgot to tell you guys, but I updated it yesterday :P.

Re: LUBE (Networking Library)

Posted: Tue Jun 15, 2010 3:51 pm
by Taehl
I don't suppose there's anyone here with networking experience and some free time, who would like to help me implement multiplayer functionality in my current project? Not just for working with Lube, but also with the multiplayer architecture (stuff like "who sends what data to whom", "how do I ensure I only send changed data", and so on).

Re: LUBE (Networking Library)

Posted: Tue Jun 15, 2010 4:41 pm
by Luiji
All I can say is that you should have the server do as much as possible to minimize cheating.

Re: LUBE (Networking Library)

Posted: Sun Sep 05, 2010 5:49 am
by kynan
-- EDIT 2 --
After some testing, it is indeed the packet size that is my current problem. Base64 quick fix seems to work plenny good.
-- END --

-- EDIT --
I'm noticing packets failing to be read properly every now and then, even using TCP. That wasn't happening before I switched to a different packeting system (after I monkeyed with LUBE). Perhaps there is more to fixing this than I thought. Also, perhaps the packets I want to send are too big.
-- END --

Hey, I noticed that the current version of LUBE only supports one level of table nesting due to improper string handling. I hacked together a quick fix using LuaSocket's mime.b64/unb64 to make sure string data didn't overlap with the separator characters. It makes the packets a bit fatter, but having good support for strings/table-nesting could be worth it. Here's the three lines I added/modified:

Code: Select all

-- ADDED BY KYNAN
mime = require "mime"
-- END

Code: Select all

function lube.bin:packvalue(i, v)
	local id = ""
	local typev = type(v)
	if typev == "string" then id = "S"
	elseif typev == "number" then id = "N"
	elseif typev == "boolean" then id = "B"
	elseif typev == "userdata"  then id = "U"
	elseif typev == "nil" then id = "0"
	else error("Type " .. typev .. " is not supported by lube.bin") return
	end
	-- MODIFIED BY KYNAN
	return tostring(id .. lube.bin.one .. i .. lube.bin.one .. (mime.b64(tostring(v))) .. lube.bin.null)
	--return tostring(id .. lube.bin.one .. i .. lube.bin.one .. tostring(v) .. lube.bin.null)
	-- END
end

Code: Select all

function lube.bin:unpackvalue(s)
	local id = s:sub(1, 1)
	s = s:sub(3)
	local len = s:find(lube.bin.one)
	local i = s:sub(1, len-1)
	i = tonumber(i) or i
	-- MODIFIED BY KYNAN
	local v = (mime.unb64(s:sub(len+1)))
	--local v = s:sub(len+1)
	-- END
	if id == "N" then v = tonumber(v)
	elseif id == "B" then v = (v == "true")
	elseif id == "0" then v = nil
	end
	return i, v
end

Re: LUBE (Networking Library)

Posted: Sun Sep 05, 2010 6:51 am
by bartbes
Oh, but it's not a bug (nor a feature), the packing is more like an example than something for production use.

About the packet size, the limit should be 8192.

Re: LUBE (Networking Library)

Posted: Sun Sep 05, 2010 4:24 pm
by kynan
Yeah. I wasn't limiting my packets properly. I'll just split them up when they get too big.