## LUBE (Networking Library)

schme16
Party member
Posts: 127
Joined: Thu Oct 02, 2008 2:46 am

### Re: LUBE (Networking Library)

bartbes wrote:You could take a look at this function here: https://github.com/Nevon/cardboard/blob ... n.lua#L181. That code uses hump.class, btw, so you might have to change the class instantiation syntax.

Thanks for the link! I noticed that I was missing the handshake when attempting to connect, this is apparently a var that must be set when connecting via tcp (I had no idea )
Cowinatub
Prole
Posts: 9
Joined: Fri Nov 09, 2012 6:13 am

### Re: LUBE (Networking Library)

Is packing still supported in the newest release?
Whenever I try and use it it just says 'Attempted to index bin(nil value)'.
qaisjp
Party member
Posts: 491
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

### Re: LUBE (Networking Library)

Can you do multiple connections for one server/client (I'd like to use TCP for message/score sharing and UDP for realtime sync)?
Or should I just use multiple servers and clients for each socket type?
Lua is not an acronym.
Lemony Lime
Prole
Posts: 22
Joined: Fri Dec 28, 2012 9:35 pm

### Re: LUBE (Networking Library)

Are there any real tutorials on how to get started with LUBE? I've found a reasonable amount of info and examples, but no real tutorials, which are always much easier to learn from. Would anyone be willing to write (or link me to, if one already exists) a simple getting started guide, for the betterment of humanity? I'm sure I'll find my way on my own eventually, but if I can avoid the extra work, I'd like to... what with college and work and all that.
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

### Re: LUBE (Networking Library)

Well, the OP points to viewtopic.php?f=5&t=230&start=210#p21112, and even though some tutorials might be old, this only means the syntax doesn't apply, the way of doing things is still mostly the same.
I've also been asked for a simple-ish example with a modern version, and then I usually link to: https://github.com/Nevon/cardboard/blob ... n.lua#L181
Frohman
Prole
Posts: 21
Joined: Sat Dec 08, 2012 12:32 pm

### Re: LUBE (Networking Library)

I'm having trouble trying to get set up with LUBE :c, I'm using the current development version and hump.class.

Code: Select all

local Vector = require "hump.vector"
local Class = require "hump.class"
require "LUBE" -- for the intertubes[
require "player"
After that I'm trying to set up a ucpClient for use, but for the life of me I can't figure out how to do this correctly, even after seeing an apparently correct implementation at https://github.com/Nevon/cardboard/blob ... n.lua#L181

Here's what two methods I've tried:

Code: Select all

local client

love.graphics.setBackgroundColor(33, 89, 125)

ip, port = cfg:match("^(.+):(%d+)$") assert(ip and port) client = lube.udpClient() client.callbacks.recv = onReceive p:load() end attempt to call field 'udpClient' (a nil value) Code: Select all local client = Class{} function love.load() love.graphics.setBackgroundColor(33, 89, 125) cfg = love.filesystem.read("userconfig.cfg") ip, port = cfg:match("^(.+):(%d+)$")
assert(ip and port)

client:include(lube.udpClient)
client:init()
end
attempt to index field 'callbacks' (a nil value)

I'm very new to networking and classes, so I'm sure I'm at fault here - if someone could tell me how, it'd be greatly appreciated!
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

### Re: LUBE (Networking Library)

This looks like it should work (the first method, anyway), are you sure the require statements are in the right place?
Frohman
Prole
Posts: 21
Joined: Sat Dec 08, 2012 12:32 pm

### Re: LUBE (Networking Library)

I think so?
Here's the entire main.lua:

Code: Select all

local Vector = require "hump.vector"
local Class = require "hump.class"
require "LUBE" -- for the intertubes
require "player"

universe = {}
p = LocalPlayer(Vector(200, 200))

local client

love.graphics.setBackgroundColor(33, 89, 125)

ip, port = cfg:match("^(.+):(%d+)\$")
assert(ip and port)

client = lube.udpClient()
end

function love.update(dt)
p:update(dt)
p:integrate(dt)
end

function love.draw()
p:draw()
end

print(data)
end

Here's another approach, this time not bothering with LOVE at all:

Code: Select all

local Class = require "hump.class"
require "LUBE"

for k,v in pairs(lube) do
print(k,v)
end
Same result - nothing is printed and the program runs successfully. Lube somehow exists but doesn't have any of its uh, fields...

I'll ask in the support subforums
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

### Re: LUBE (Networking Library)

I've updated the repository, so LUBE is now a directory, instead of a single monolithic file, and it now also ships with a fallback class commons implementation (I still encourage you to use your own, though). Furthermore, I've added a conditional enet backend, to prepare for 0.9.0, I figured some of you might be interested in that too. Of course, since it's restricted to the LUBE api, it's less powerful than using it directly, but it does mean users can now easily switch, and it's still the same, simple api.
ArchAngel075
Party member
Posts: 317
Joined: Mon Jun 24, 2013 5:16 am

### Re: LUBE (Networking Library)

Im not exactly sure how to set callbacks, i first tried defining them like :

Code: Select all

function server.callbacks.connect(clientid)
--
end

but i error with attempt to index 'server' (nil value)

next i tried :

Code: Select all

function onConnect(clientid)
print("Client Connected")
end