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

Showcase your libraries, tools and other projects that help your fellow love users.
CherryBit
Prole
Posts: 2
Joined: Sun Dec 18, 2016 12:48 pm

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

Post 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.
User avatar
Ikroth
Citizen
Posts: 79
Joined: Thu Jul 18, 2013 4:44 am

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

Post 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.
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

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

Post 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!
User avatar
Ikroth
Citizen
Posts: 79
Joined: Thu Jul 18, 2013 4:44 am

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

Post 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.
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

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

Post 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:
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

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

Post 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?
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

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

Post 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
User avatar
emanevitaerc
Prole
Posts: 17
Joined: Sun Mar 13, 2016 7:21 am

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

Post by emanevitaerc »

Just, wow. I'll absolutely be following this as development goes along. Definitely going to use this, great work.
User avatar
Ikroth
Citizen
Posts: 79
Joined: Thu Jul 18, 2013 4:44 am

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

Post 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.
User avatar
Ikroth
Citizen
Posts: 79
Joined: Thu Jul 18, 2013 4:44 am

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

Post 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/
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests