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) v0.04 + LUBE-X v0.02

Post by bartbes »

LAN-discovery: Don't know, let me look it up in the LuaSocket manual

Packages not dropping: Same for this.. I guess they should be dropped automatically, let's see if I have to set something in LuaSocket

EDIT: I have to enable allowing broadcast first, scheduled for next version
EDIT2: Can't find anything about packet dropping, but let me explain how you can already enable broadcasting:

Code: Select all

--single connection
love.client.Init()
love.client.socket:setoption("broadcast", true)
--multiple connections
conn = love.client()
conn.socket:setoption("broadcast", true)
setoption return 1 on success, nil and an error on failure (so is assert-compatible)
Matkins
Citizen
Posts: 53
Joined: Mon Mar 23, 2009 5:12 pm

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

Post by Matkins »

Hi bartbes and everyone,

I've been trying to learn how to use LUBE so I can make my games multiplayer, I'm not finding it very easy, the docs on the wiki don't enlighten me much. Are there any tutorials around, or does anyone care to throw one together?

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

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

Post by bartbes »

No time for a full tutorial, but let me give you a quick introduction:
Client:

Code: Select all

love.filesystem.require("LUBE.lua") --load the file, obviously

function rcvCallback(data)
    --data is the data received, do anything you want with it
end

function load()
    --do anything else you need to do here
    lube.client.Init() --initialize
    lube.client.setHandshake("Hi!") --this is a unique string that will be sent when connecting and disconnecting
    lube.client.setCallback(rcvCallback) --set rcvCallback as the callback for received messages
    lube.client.connect(ip, port) --change ip and port into.. an ip and a port
end

function update(dt)
    lube.client.update() --usually you call this before anything else, so you always work with updated variables
    --anything else
end

function draw()
    --nothing special here
end
Server:

Code: Select all

love.filesystem.require("LUBE.lua")

function connCallback(ip, port) --when a client connects
    --do something
end

function rcvCallback(data, ip, port) --same as in client, but also receives ip and port of sender
end

function disconnCallback(ip, port) --when a client disconnects
end

function load()
    --anything
    lube.server.Init(port) --again, change port
    lube.server.setCallback(rcvCallback, connCallback, disconnCallback) --set the callbacks
    lube.server.setHandshake("Hi!") --should be the same as the client
end

function update(dt)
    lube.server.update() --same story as client
end

function draw()
end
Hope this helps
Matkins
Citizen
Posts: 53
Joined: Mon Mar 23, 2009 5:12 pm

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

Post by Matkins »

When i try to start up the server I get this error:

Code: Select all

LUBE.lua:303: attempt to index local 'self' (a number value)

Stack traceback:
LUBE.lua:303: in function 'Init'
main.lua:20: in function <main.lua:18>
main.lua:20 being "lube.server.Init(8118)"

I've tried using all sorts of port numbers, I don't understand.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post by bartbes »

Oops, something I keep forgetting myself, you should use
lube.server:Init (the : )
this applies for every other lube function as well
User avatar
Sparx
Party member
Posts: 125
Joined: Thu Apr 02, 2009 9:54 am
Location: Aachen, Germany

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

Post by Sparx »

If you need information about LUBE take a look at LUBE-X downloadable at the main page... The source allso applies to LUBE.lua but you have to call the functions by lube.thefunction

If it's about the generall structure of Game-Networking tak-e a close look at:

-http://gafferongames.com/networking-for ... ogrammers/
-http://developer.valvesoftware.com/wiki ... Networking
-http://developer.valvesoftware.com/wiki ... mpensation

I know it takes some time to read all the articels you can find about this topic, but it definatly helps planing. The more you plan this the faster you will have great results.
Matkins
Citizen
Posts: 53
Joined: Mon Mar 23, 2009 5:12 pm

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

Post by Matkins »

Thanks Bartbes and Sparx, thanks to your help I have made some progress with my networked game.

However, I appear to be experiencing a similar problem to Sparx on the previous page. At first the server recieves the client's data instantly (as far as a human is concerned), but then gradually over time it gets slower and slower. Did either of you manage to resolve this problem?
User avatar
Sparx
Party member
Posts: 125
Joined: Thu Apr 02, 2009 9:54 am
Location: Aachen, Germany

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

Post by Sparx »

I did: following solution aplies to the actual LUBE version:

Every second the server sends a ping to the client which the clienbt needs to respond to. This will tell the server the ping time etc... but it doesn't really matter

In my own "PING" the server sends his local time so love.timer....
If the time between 2 of these packages is biger than the difference of the timestamp in the packages then there is something wrong... the client seems to be too slow, so a longer "REcieveCycle" is needed.....
the more often you have lube.client:update() running the more data you can get out of your port.

this one:
for i=0,math.ceil(RecieveCycle) do
lube.client:update()
end

Now the second good help: don't send data too often... every 20-30 ms MUST be enough this keeps the serverinput small

if(sendTimer>=0.03) then sendTimer=0 sendData() end


I hope this helps....
By the way. I hope the next lube version has some solution like this integrated
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post by bartbes »

Looks like a nice solution, but I'm more interested in a way to remove the problem instead of working around it. Too bad the Lag-o-Meter didn't show problems, this leaves me confused about the problem. One thing that might help, did one of you try it without the inbuilt ping? Maybe that's flooding the connection.
User avatar
Sparx
Party member
Posts: 125
Joined: Thu Apr 02, 2009 9:54 am
Location: Aachen, Germany

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

Post by Sparx »

i really don't like the inbuilt ping thing.. i don't use it! What is flooding is that you send data every frame... more often than the other side is abel to catch them...
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests