LUBE (Networking Library)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post 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.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: LUBE (Networking Library)

Post by thelinx »

Hey.
Hey.

Re-upload it.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post by bartbes »

Easy dude, easy, I'm releasing a new version.. soon.
User avatar
Chief
Party member
Posts: 101
Joined: Fri Mar 12, 2010 7:57 am
Location: Norway, 67° north

Re: LUBE (Networking Library)

Post by Chief »

bartbes wrote:Easy dude, easy, I'm releasing a new version.. soon.
...GIEF.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post by bartbes »

Forgot to tell you guys, but I updated it yesterday :P.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: LUBE (Networking Library)

Post 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).
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Luiji
Party member
Posts: 396
Joined: Mon May 17, 2010 6:59 pm

Re: LUBE (Networking Library)

Post by Luiji »

All I can say is that you should have the server do as much as possible to minimize cheating.
Good bye.
kynan
Prole
Posts: 2
Joined: Thu Aug 26, 2010 11:48 pm

Re: LUBE (Networking Library)

Post 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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post 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.
kynan
Prole
Posts: 2
Joined: Thu Aug 26, 2010 11:48 pm

Re: LUBE (Networking Library)

Post by kynan »

Yeah. I wasn't limiting my packets properly. I'll just split them up when they get too big.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests