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

BorhilIan
Prole
Posts: 31
Joined: Wed Mar 15, 2017 6:46 am

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

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?

Sir_Silver
Party member
Posts: 282
Joined: Mon Aug 22, 2016 2:25 pm

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

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. problem solved

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

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

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

Sir_Silver
Party member
Posts: 282
Joined: Mon Aug 22, 2016 2:25 pm

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

Yeah that makes perfect sense, silly me.

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

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.

Sir_Silver
Party member
Posts: 282
Joined: Mon Aug 22, 2016 2:25 pm

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

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.

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

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.
Lua is not an acronym.

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

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

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).

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

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.

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

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

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

### Who is online

Users browsing this forum: Google [Bot] and 1 guest