LUBE (Networking Library)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
schme16
Party member
Posts: 127
Joined: Thu Oct 02, 2008 2:46 am

Re: LUBE (Networking Library)

Post by schme16 » Mon May 28, 2012 2:00 pm

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 :shock:)
My Development Diary - http://shanegadsby.info

Cowinatub
Prole
Posts: 9
Joined: Fri Nov 09, 2012 6:13 am

Re: LUBE (Networking Library)

Post by Cowinatub » Sat Nov 10, 2012 3:32 am

Is packing still supported in the newest release?
Whenever I try and use it it just says 'Attempted to index bin(nil value)'.

User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: LUBE (Networking Library)

Post by qaisjp » Mon Dec 10, 2012 7:18 pm

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.

User avatar
Lemony Lime
Prole
Posts: 22
Joined: Fri Dec 28, 2012 9:35 pm

Re: LUBE (Networking Library)

Post by Lemony Lime » Sat Jan 19, 2013 4:50 am

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.

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 » Sat Jan 19, 2013 9:32 am

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)

Post by Frohman » Sun Feb 24, 2013 2:59 pm

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

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 = 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()
	client.callbacks.recv = onReceive
	p:load()
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!

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 » Sun Feb 24, 2013 3:13 pm

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)

Post by Frohman » Sun Feb 24, 2013 3:18 pm

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

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 = lube.udpClient()
	client.callbacks.recv = onReceive
	p:load()
end

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

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

function onReceive(data)
	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

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 » Sun Jul 21, 2013 1:18 pm

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.

User avatar
ArchAngel075
Party member
Posts: 317
Joined: Mon Jun 24, 2013 5:16 am

Re: LUBE (Networking Library)

Post by ArchAngel075 » Fri Oct 04, 2013 2:18 pm

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

function love.load()
 -- create the server etc
 server.callbacks.connect = onConnect
end
but this seems to not work as when my client connects i have no message.
Also i have made sure if the server and clients work, i can have a client send a message and then do server:receive() with success.
I also used print(not not server.callbacks) to check if the callbacks table exists and the function is assigned.

-end-

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests