LUBE (Networking Library)

Showcase your libraries, tools and other projects that help your fellow love users.
stampede
Prole
Posts: 21
Joined: Fri Oct 23, 2009 8:22 am
Location: Finland
Contact:

Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02

Post by stampede »

Alrighty currently making really simple networked test game. But I just can't figure out this problem with pack and unpack...

Code: Select all

-- client packs and sends data to the server
datatable = { player.x,player.y };
data = lube.bin:pack( datatable );
lube.client:send( data );

Code: Select all

-- server gets data and unpacks it to a string
function recv(data, ip)
	datatable = lube.bin:unpack( data );
	str = ip .. " x: " .. tostring( datatable[1] ) .. " y: " .. tostring( datatable[2] );
end
Am I using packing wrong? It can receive if I only send player.x normally without packing to the server. This just gives this:

Code: Select all

127.0.0.1 x: nil y: nil
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02

Post by bartbes »

I think.. it might work if you use datatable["1"], if I read the code correctly it always assumes the indexes are strings.
stampede
Prole
Posts: 21
Joined: Fri Oct 23, 2009 8:22 am
Location: Finland
Contact:

Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02

Post by stampede »

Thanks it works now, but weird it wants that number in string format :? Is it normally that way, or just in this how I've set it up?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02

Post by bartbes »

It's in lube.bin, I might change it when I create the next update..
stampede
Prole
Posts: 21
Joined: Fri Oct 23, 2009 8:22 am
Location: Finland
Contact:

Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02

Post by stampede »

I'm not really wrapped my head around this yet myself, but I'll ask anyway:

I want to setup a server accepting tcp and udp. Using tcp for things like login and udp for things like normal moving. What's good way to use these? I think lube.server:receive() uses protocol you've setup in Init, but what if I init tcp AND udp for different ports?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02

Post by bartbes »

The second will overwrite the first, HOWEVER, IIRC you can create multiple instances of servers and clients, I'll look it up and report back in a sec.

EDIT: Oh, right, I remember, you can call lube.client() and lube.server() (with the args to init), it returns a client/server object. (works best if you do that before initing the general table) Keep in mind that they don't (or shouldn't) share a client table.

EDIT2: OMG I screwed up, bad, it does share a client table, so... I'll add it to my todo list :P
stampede
Prole
Posts: 21
Joined: Fri Oct 23, 2009 8:22 am
Location: Finland
Contact:

Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02

Post by stampede »

Hmm, so it's like after I've inited tcp server first I,

Code: Select all

lube.server:Init(1234, tcp);
tcp_server = lube.server();
and can use that like:

Code: Select all

tcp_server:receive();
?

I'm guessing it's not like that at all :(

EDIT: it's really useful if I can use tcp and udp both for one client, so that should be in Lube. It's not good to try to login with udp :D
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02

Post by bartbes »

No.., first you messed up the order, create a server object before you init it, and the arguments to lube.server are the arguments you normally pass to Init, so the object returned is already Inited, the last statement (the receive one) should work.

EDIT (you edited while I was posting): Yes, currently that'd fail, but technically it supports it.. just wait until I fix the client table things, I just put it on my todo list for tomorrow.
stampede
Prole
Posts: 21
Joined: Fri Oct 23, 2009 8:22 am
Location: Finland
Contact:

Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02

Post by stampede »

Code: Select all

tcp_server = lube.server() -- copies all the needed data to tcp_server
tcp_server:Init(1234, tcp) -- Inits it with decired port and protocol
Like this then? You said the object would be already inited, but how could it be inited when I haven't given its port and protocol yet? :? Man this is confusing.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02

Post by bartbes »

Pass the same arguments you'd normally pass to Init to lube.server, I'll give you an example on how this might work (it doesn't, but the result is the same)

Code: Select all

function lube.server(...)
   local t = {}--create the object
   --do some fairy magic
   t:Init(...)
   return t
end
So, tcp_server = lube.server(1234, tcp) (btw, shouldn't it be "tcp", I can't remember anymore..)
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests