Page 18 of 34
Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02
Posted: Mon Dec 28, 2009 6:54 pm
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:
Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02
Posted: Mon Dec 28, 2009 7:18 pm
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.
Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02
Posted: Mon Dec 28, 2009 7:29 pm
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?
Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02
Posted: Mon Dec 28, 2009 8:42 pm
by bartbes
It's in lube.bin, I might change it when I create the next update..
Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02
Posted: Tue Dec 29, 2009 10:10 pm
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?
Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02
Posted: Tue Dec 29, 2009 10:15 pm
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
Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02
Posted: Tue Dec 29, 2009 10:22 pm
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:
?
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
Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02
Posted: Tue Dec 29, 2009 10:26 pm
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.
Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02
Posted: Tue Dec 29, 2009 10:30 pm
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.
Re: LUBE (Networking Library) v0.6.1 + LUBE-X v0.02
Posted: Tue Dec 29, 2009 10:37 pm
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..)