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.
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
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
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.
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.
(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.
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?
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?
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.
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?
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?