Page 3 of 9

Re: sock.lua - A simple networking library for LÖVE

Posted: Sun Dec 18, 2016 1:06 pm
by CherryBit
Just have to say that I love this library. I've used it multiple times for online multiplayer games and has been easy to work with. I can't recommend it enough for people who want to start playing around with networking.

My only real feedback would be:

- I think logging all events is a bit much. Typically I changed it to just log errors and warnings because otherwise in usage it can bloat memory usage. I'm guessing the current implementation is just a stop-gap until it writes logs once they reach a certain length, but it feels a bit like a "gotcha" right now.

- Might be helpful to people unfamiliar how to include a short blurb of how to set up a dedicated server. (i.e get LuaJIT, install/make enet and other dependencies, etc) But I understand that's a topic that can easily grow to be quite lengthy and in depth, and could just be out of your intended scope.

Re: sock.lua - A simple networking library for LÖVE

Posted: Sun Dec 18, 2016 7:30 pm
by Ikroth
CherryBit wrote: - I think logging all events is a bit much. Typically I changed it to just log errors and warnings because otherwise in usage it can bloat memory usage. I'm guessing the current implementation is just a stop-gap until it writes logs once they reach a certain length, but it feels a bit like a "gotcha" right now.
I agree, the logging functionality is sorely lacking at the moment. I'd like to keep some logging ability, but I don't want to use up lots of memory or silently create huge log files. One option would be to keep logging completely minimal by default (print to stdout only) and then have the option of redirecting to a log file if needed. I would accept pull requests to expand and improve the logging.
CherryBit wrote: - Might be helpful to people unfamiliar how to include a short blurb of how to set up a dedicated server. (i.e get LuaJIT, install/make enet and other dependencies, etc) But I understand that's a topic that can easily grow to be quite lengthy and in depth, and could just be out of your intended scope.
I would expect most people to just do ad-hoc networking, but I think this information would be useful to put somewhere. As you said, it probably lies outside the scope of this library though. Installing LuaJIT and enet to run a dedicated LOVE server is more of a general LOVE/Lua topic than it is a sock.lua topic.

Re: sock.lua - A simple networking library for LÖVE

Posted: Thu Feb 02, 2017 7:51 am
by Ulydev
Hello!
Ikroth wrote:sock.lua
I'm making a turn-based game and I'd like to set up an authoritative server-client architecture. I need multiple rooms and matchmaking.
I was thinking of creating a rooms table server-side to store client sockets in each room. Then whenever I want to send a message to a specific room I'd just iterate over the rooms[id] table and send a message to each socket.
Or, I'd simply use :setSendChannel(roomId). Is that its purpose?

Thanks!

Re: sock.lua - A simple networking library for LÖVE

Posted: Thu Feb 02, 2017 1:33 pm
by Ikroth
Ulydev wrote:Hello!
Ikroth wrote:sock.lua
I'm making a turn-based game and I'd like to set up an authoritative server-client architecture. I need multiple rooms and matchmaking.
I was thinking of creating a rooms table server-side to store client sockets in each room. Then whenever I want to send a message to a specific room I'd just iterate over the rooms[id] table and send a message to each socket.
Or, I'd simply use :setSendChannel(roomId). Is that its purpose?

Thanks!
Channels send data concurrently over the network, you can use that functionality in any way you would like. If you send a reliable message and it is not received on the other end, that can cause delay on that channel, because it has to resend the packet. Packets on other channels are not affected by this. Common things to send separately might be physics, chat, and files. Things unimportant to the actual gameplay should not affect network latency.

I would suggest that you keep the number of channels small, because I don't think channels were intended to scale up to hundreds, but it's possible.

Re: sock.lua - A simple networking library for LÖVE

Posted: Thu Feb 02, 2017 6:08 pm
by Ulydev
Ikroth wrote:-
Thanks for your answer! I need a few hundred channels in my case (or game rooms, more specifically), so I guess I'll implement my own :broadcastToGameRoom() method :awesome:

Re: sock.lua - A simple networking library for LÖVE

Posted: Tue Mar 14, 2017 5:25 pm
by Ulydev
Ikroth wrote:sock.lua
Hello there, I'm trying to send some data on client connect (e.g. client version, client name), but whatever I put in client:connect(), the server doesn't get the data.

Code: Select all

--client
client:connect()

--server
server:on("connect", function( data, client )
  print(data) --always displays "0"
end)
How should I do it?

Re: sock.lua - A simple networking library for LÖVE

Posted: Tue Mar 14, 2017 5:48 pm
by Sir_Silver
My roundabout solution for this would be to use another event that you send when the client connects to the server, like such:

Code: Select all

client:on("connect", function(data)
    client:send("version", {love.getVersion()})  --love.getVersion returns multiple args, so we have to store them in a table and then send it.
end)

server:on("version", function(version, client)
    --Do stuff with the client's version, like kick them if they don't have the right one.
end)
So when the client connects to the server, it will then send a message to the server with the clients version, (and whatever else you may want to send) and do stuff with that. :P

Re: sock.lua - A simple networking library for LÖVE

Posted: Wed Mar 15, 2017 4:01 pm
by emanevitaerc
Just, wow. I'll absolutely be following this as development goes along. Definitely going to use this, great work.

Re: sock.lua - A simple networking library for LÖVE

Posted: Wed Mar 15, 2017 5:51 pm
by Ikroth
Ulydev wrote: Tue Mar 14, 2017 5:25 pm
Ikroth wrote:sock.lua
Hello there, I'm trying to send some data on client connect (e.g. client version, client name), but whatever I put in client:connect(), the server doesn't get the data.

Code: Select all

--client
client:connect()

--server
server:on("connect", function( data, client )
  print(data) --always displays "0"
end)
How should I do it?
Sir_Silver wrote: Tue Mar 14, 2017 5:48 pm My roundabout solution for this would be to use another event that you send when the client connects to the server, like such:

Code: Select all

client:on("connect", function(data)
    client:send("version", {love.getVersion()})  --love.getVersion returns multiple args, so we have to store them in a table and then send it.
end)

server:on("version", function(version, client)
    --Do stuff with the client's version, like kick them if they don't have the right one.
end)
So when the client connects to the server, it will then send a message to the server with the clients version, (and whatever else you may want to send) and do stuff with that. :P
This would be the way to do it for right now. The :connect() function is supposed to allow you to send an integer, but it would be nice if it at least let you send a table.

Also, I'm going to work on some updates soon. There's some enet functions that I haven't implemented yet, somehow. And if anyone here knows about adding networking to Travis CI, send me a message.

Re: sock.lua - A simple networking library for LÖVE

Posted: Sat Mar 18, 2017 6:36 pm
by Ikroth
Apologies for the double post, but I have released version 0.3.0 of sock.lua!

https://github.com/camchenry/sock.lua/r ... /tag/0.3.0

A brief changelog of some of the changes:
  • Renamed 'data format' to 'schema'
    • Server:setDataFormat is now Server:setSchema
    • Added Client:setSchema
  • Added enet's range coding compression
    • Added Server:enableCompression
    • Added Client:enableCompression
  • Added optional code for Client:connect
  • Added Server:getClientCount
  • Added Server:destroy
  • Added Client:reset
  • Added Client:isConnected
  • Added Client:isConnecting
  • Added Client:isDisconnected
  • Added Client:isDisconnecting
I've also fixed the continuous integration builds, and I'm working on getting the coverage to at least 75%.

You can check out the repository here: https://github.com/camchenry/sock.lua and the documentation here: http://camchenry.com/sock.lua/