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

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
BorhilIan
Prole
Posts: 35
Joined: Wed Mar 15, 2017 6:46 am

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

Post by BorhilIan » Sun Mar 19, 2017 4:56 am

My only question is how is this libraries binary performance? To reiterate how much overhead to each packet is there, can it be used to send/receive unsigned integers of varying bit or byte length?

User avatar
Sir_Silver
Party member
Posts: 283
Joined: Mon Aug 22, 2016 2:25 pm

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

Post by Sir_Silver » Sat Jun 03, 2017 11:07 am

I've been working on making something with your library and I'm having some issues with the disconnect event. It doesn't seem to be getting called on the client or server, even though I have callbacks defined for both client and server, when I have a client disconnect. I'm gonna check the source code, but I'm guessing that disconnect doesn't actually get called when a client disconnects?

Edit: It actually does work, it just seems that I needed to add a timer between connecting and disconnecting, so I guess I can't just connect and disconnect in the same frame. :P problem solved

User avatar
Nuthen224
Citizen
Posts: 50
Joined: Sun Jul 28, 2013 9:40 pm

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

Post by Nuthen224 » Sun Jun 04, 2017 12:39 am

I think the reason for that might be that connect doesn't get processed until the server/client update.

User avatar
Sir_Silver
Party member
Posts: 283
Joined: Mon Aug 22, 2016 2:25 pm

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

Post by Sir_Silver » Sun Jun 04, 2017 12:52 am

Yeah that makes perfect sense, silly me. :P

User avatar
Monster psychic cat
Prole
Posts: 4
Joined: Wed Mar 01, 2017 9:29 pm
Location: South America
Contact:

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

Post by Monster psychic cat » Fri Jun 09, 2017 1:22 am

Hello there.
I've been staring at my code in a text editor for hours trying to understand what I'm doing wrong. I keep getting a "Error during service" error (sock.lua - line 721), and tracing back doesn't tell me much.

My code (hope I'm not doing something dumb):

Code: Select all

-- client
local sock = require "sock"
local address, port = "localhost", 12345
local cnet = sock.newClient(address, port, 2)

-- connection callback
cnet:on("connect", function(data, client)
    print("connecting...")
end)

-- custom callback
cnet:on("hello", function(msg)
    print("what's this? " .. msg)
end)

function love.update(dt)
    cnet:update()
end

Code: Select all

-- server (doesn't run on LÖVE)
local sock = require "sock"
local snet = sock.newServer("*", 12345, 8, 2)

snet:on("connect", function(data, client)
    client:send("hello", "oh hey!")
end)

while true do
    snet:update()
end
Lua is not an acronym.

User avatar
Sir_Silver
Party member
Posts: 283
Joined: Mon Aug 22, 2016 2:25 pm

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

Post by Sir_Silver » Fri Jun 09, 2017 4:48 am

The reason you're getting that error is because you haven't actually connected the client to the server. Call cnet:connect() at the end of your client file.

User avatar
Monster psychic cat
Prole
Posts: 4
Joined: Wed Mar 01, 2017 9:29 pm
Location: South America
Contact:

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

Post by Monster psychic cat » Fri Jun 09, 2017 10:22 pm

Sir_Silver wrote:
Fri Jun 09, 2017 4:48 am
The reason you're getting that error is because you haven't actually connected the client to the server. Call cnet:connect() at the end of your client file.
I have done that... and it's still giving me a error.
Image
Lua is not an acronym.

User avatar
Ikroth
Citizen
Posts: 70
Joined: Thu Jul 18, 2013 4:44 am

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

Post by Ikroth » Sat Jun 10, 2017 12:35 am

It may help to post more of your code. I don't see anything obviously wrong with the screenshot that you posted. "Error during service" is just enet's generic error message that doesn't return any more information than the message itself. I would check a couple of things to just make sure its working: use an IPv4 address, make sure both the client and server have bitser (or some other serialization library) and are using it, and make sure that server was actually bound to the port (using something like netstat).

User avatar
Monster psychic cat
Prole
Posts: 4
Joined: Wed Mar 01, 2017 9:29 pm
Location: South America
Contact:

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

Post by Monster psychic cat » Sat Jun 10, 2017 1:14 am

Apparently, rewriting the code from scratch just to make a new .love file to test didn't bring up the crash anymore - and just using that code in my main game fixed it?????????????

In turn, I lost all of my previous networking code. However, I was already planning to rewrite my code. Thanks anyway!
Lua is not an acronym.

User avatar
Ikroth
Citizen
Posts: 70
Joined: Thu Jul 18, 2013 4:44 am

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

Post by Ikroth » Sat Jun 10, 2017 1:22 am

I'm glad you were able to fix the issue. Let me know if you figure out what the original issue was.

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests