LUBE (Networking Library)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

A little help with LUBE

Post by TechnoCat »

Having trouble getting started using LUBE?

Selected posts from this thread.
Quick introduction (arguably the most useful for starting)
http://love2d.org/forums/viewtopic.php? ... =120#p6154
Out of date examples
http://github.com/bartbes/lube-demo
Very simple start
http://love2d.org/forums/viewtopic.php? ... t=30#p2905
http://love2d.org/forums/viewtopic.php? ... 190#p15526
Pack and Unpack (no nested tables in lube.bin:pack/unpack
http://love2d.org/forums/viewtopic.php? ... 170#p11178
Multiple connections to a server
http://love2d.org/forums/viewtopic.php? ... =100#p6079
Broadcasting to a subnet
http://love2d.org/forums/viewtopic.php? ... =120#p6151
http://love2d.org/forums/viewtopic.php? ... =150#p7029

Selected General Network Programming Guides:
Networking for Game Programmers
Targeting A variation of dead reckoning
Source Multiplayer Networking
FAQ - Multiplayer and Network Programming
Distributing Object State for Networked Games Using Object Views
What is Lag?
Using Groupings for Networked Gaming

A very simple LOVE server/client skeleton.
LUBEMinimalSkeleton.love
LOVE 0.7.0
LUBE 0.7.1
MiddleClass + Stateful
(12.85 KiB) Downloaded 1627 times
All this does is connect to a server on localhost. And the server acknowledges the connection.
You will have to open up two instances of it, one for server, and then one for client.
Press 1 for server, Press 2 for client.

In a nutshell, this is what is happening:
server:

Code: Select all

function onConnect(ip, port)
  print("Connection from " .. ip)
end
function onReceive(data, ip, port)
  
end
function onDisconnect(ip, port)
  
end
server = lube.server(18025)
server:setCallback(onReceive, onConnect, onDisconnect)
server:setHandshake("Hi!")

function love.update(dt)
  server:update(dt)
end
client:

Code: Select all

function onReceive(data)
  
end
client = lube.client()
client:setHandshake("Hi!")
client:setCallback(onReceive)
client:connect("127.0.0.1", 18025)

function love.update(dt)
  client:update(dt)
end
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: LUBE (Networking Library)

Post by TechnoCat »

How is a server supposed to be restarted? double post was intentional by the way.

For instance in this program.
Open up an instance, press 1 to turn it into a server.
Open up another instance on localhost and press 2 to turn it into a client.
Observe they made a connection and you can see the cursor on the server instance.
On the server instance, press escape to go back to the menu, and then press 1 to go to server again.
Turn the client instance back into a client.
No connection is made.

This happens because I am unsure how to properly disconnect and reinitialize a server.
Attachments
LUBE Server Restart.love
0.7.0
(15.23 KiB) Downloaded 484 times
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 »

It probably works if you call lube.server.socket:close(), but it is not exposed directly in LUBE.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: A little help with LUBE

Post by kikito »

TechnoCat wrote: A very simple LOVE server/client skeleton.
I still think this could be done simpler - at least one of the classes (NetTest or Game) isn't really needed. Also, I don't like having the love.xxx functions redefined on each state.

I'll see if I can provide my own version this evening.
When I write def I mean function.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: LUBE (Networking Library)

Post by kikito »

(double posting since previous post was this morning)

This is my take on the minimalskeleton thingie.

Super-warning: I can't test the code on the computer I'm using for writing this, so the code is completely untested. I'm not able to debug it, though. Pretty sure there are syntax errors etc. Technocat, would you kindly?

The structure is simpler (everything is done by the class Game) and the callbacks management is more streamlined. Also, using self on the server and client minimizes global variables.
Attachments
LUBEMinimalSkeleton.love
(13.64 KiB) Downloaded 487 times
When I write def I mean function.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: LUBE (Networking Library)

Post by TechnoCat »

kikito wrote:Super-warning: I can't test the code on the computer I'm using for writing this, so the code is completely untested. I'm not able to debug it, though. Pretty sure there are syntax errors etc. Technocat, would you kindly?

The structure is simpler (everything is done by the class Game) and the callbacks management is more streamlined. Also, using self on the server and client minimizes global variables.
Well, I fixed it up and it runs and makes connections, but the thing is, now that Game and Server are states of the same object, how do you draw the game and still run a server or client at the same time?
Attachments
kikito LUBE skeleton.love
0.7.0
(13.17 KiB) Downloaded 502 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post by Robin »

TechnoCat wrote:the thing is, now that Game and Server are states of the same object, how do you draw the game and still run a server or client at the same time?
Maybe with pushState()?
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: LUBE (Networking Library)

Post by kikito »

TechnoCat wrote:how do you draw the game and still run a server or client at the same time?
well, then it wouldn't be a minimal skeleton any more, would it ? :)

Pushing states could be an option, but it would be a bit tricky. A more proper way to do it probably involves threads/corroutines. Or maybe a separate state called ServerClient.
When I write def I mean function.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: LUBE (Networking Library)

Post by zac352 »

The documentation was useless in teaching me how to make server information broadcast to all clients... Is it possible to enumerate through local area clients?
Hello, I am not dead.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: LUBE (Networking Library)

Post by TechnoCat »

zac352 wrote:The documentation was useless in teaching me how to make server information broadcast to all clients... Is it possible to enumerate through local area clients?
I think you would find my post quite helpful. http://love2d.org/forums/posting.php?mo ... 49#pr21112
It even has these two links about broadcasting to certain clients. Seems like you might want to broadcast to the 192.168.x.x subnet?
http://love2d.org/forums/viewtopic.php? ... =120#p6151
http://love2d.org/forums/viewtopic.php? ... =150#p7029
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests