LUBE (Networking Library)

Showcase your games and demos, and discuss ongoing projects.

A little help with LUBE

Postby TechnoCat on Sun Oct 24, 2010 8:57 pm

Having trouble getting started using LUBE?

Selected posts from this thread.
Quick introduction (arguably the most useful for starting)
viewtopic.php?f=5&t=230&start=120#p6154
Out of date examples
http://github.com/bartbes/lube-demo
Very simple start
viewtopic.php?f=5&t=230&start=30#p2905
viewtopic.php?f=5&t=230&start=190#p15526
Pack and Unpack (no nested tables in lube.bin:pack/unpack
viewtopic.php?f=5&t=230&start=170#p11178
Multiple connections to a server
viewtopic.php?f=5&t=230&start=100#p6079
Broadcasting to a subnet
viewtopic.php?f=5&t=230&start=120#p6151
viewtopic.php?f=5&t=230&start=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 1071 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: 1610
Joined: Thu Jul 30, 2009 12:31 am
Location: Chicago, IL

Re: LUBE (Networking Library)

Postby TechnoCat on Wed Nov 03, 2010 4:03 am

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 183 times
User avatar
TechnoCat
Inner party member
 
Posts: 1610
Joined: Thu Jul 30, 2009 12:31 am
Location: Chicago, IL

Re: LUBE (Networking Library)

Postby bartbes on Wed Nov 03, 2010 6:45 am

It probably works if you call lube.server.socket:close(), but it is not exposed directly in LUBE.
Cowardly acts and the eating of birds must not be the deeds of a Hero of Storms.
User avatar
bartbes
Sex machine
 
Posts: 4376
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands

Re: A little help with LUBE

Postby kikito on Wed Nov 03, 2010 9:35 am

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: 2789
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain

Re: LUBE (Networking Library)

Postby kikito on Thu Nov 04, 2010 12:45 am

(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 178 times
When I write def I mean function.
User avatar
kikito
Inner party member
 
Posts: 2789
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain

Re: LUBE (Networking Library)

Postby TechnoCat on Thu Nov 04, 2010 2:07 am

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 206 times
User avatar
TechnoCat
Inner party member
 
Posts: 1610
Joined: Thu Jul 30, 2009 12:31 am
Location: Chicago, IL

Re: LUBE (Networking Library)

Postby Robin on Thu Nov 04, 2010 7:09 am

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
Robin
The Omniscient
 
Posts: 6242
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands

Re: LUBE (Networking Library)

Postby kikito on Thu Nov 04, 2010 7:52 am

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
kikito
Inner party member
 
Posts: 2789
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain

Re: LUBE (Networking Library)

Postby zac352 on Fri Nov 05, 2010 8:54 pm

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
zac352
Party member
 
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.

Re: LUBE (Networking Library)

Postby TechnoCat on Fri Nov 05, 2010 10:41 pm

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. posting.php?mode=quote&f=5&p=21649#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?
viewtopic.php?f=5&t=230&start=120#p6151
viewtopic.php?f=5&t=230&start=150#p7029
User avatar
TechnoCat
Inner party member
 
Posts: 1610
Joined: Thu Jul 30, 2009 12:31 am
Location: Chicago, IL

PreviousNext

Return to Projects and Demos

Who is online

Users browsing this forum: Muris, Yahoo [Bot] and 9 guests