Page 22 of 34

A little help with LUBE

Posted: Sun Oct 24, 2010 8:57 pm
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 1603 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

Re: LUBE (Networking Library)

Posted: Wed Nov 03, 2010 4:03 am
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.

Re: LUBE (Networking Library)

Posted: Wed Nov 03, 2010 6:45 am
by bartbes
It probably works if you call lube.server.socket:close(), but it is not exposed directly in LUBE.

Re: A little help with LUBE

Posted: Wed Nov 03, 2010 9:35 am
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.

Re: LUBE (Networking Library)

Posted: Thu Nov 04, 2010 12:45 am
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.

Re: LUBE (Networking Library)

Posted: Thu Nov 04, 2010 2:07 am
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?

Re: LUBE (Networking Library)

Posted: Thu Nov 04, 2010 7:09 am
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()?

Re: LUBE (Networking Library)

Posted: Thu Nov 04, 2010 7:52 am
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.

Re: LUBE (Networking Library)

Posted: Fri Nov 05, 2010 8:54 pm
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?

Re: LUBE (Networking Library)

Posted: Fri Nov 05, 2010 10:41 pm
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