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

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
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 11, 2017 12:21 am

Ikroth, is it normal/expected behavior for clients to remain connected to a server after the server calls :destroy() on itself? Right now after destroying my server clients remain connected, so I''m opting to iterate through the clients on the server and have them call :disconnect().

I looked through sock.lua and found that server:destroy() calls self.host:destroy(), but host is defined as nil, is this just something that has been in the works/ just wasn't developed yet?

Thanks for your time. =)

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 » Sun Jun 11, 2017 4:18 am

Destroying the host just means it will immediately unbind itself from the port and trash the pointers to any resources. So yes, you would need to go through all of the clients and send them a disconnect message.

I'm not sure I'd want to automatically disconnect clients since you may want to handle it differently, like waiting until all clients acknowledge the disconnect to actually destroy the server.

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 11, 2017 5:28 am

Cool, thank you for responding. Just wanted to make sure that I wasn't doing anything too stupid :)

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 » Tue Jun 13, 2017 12:06 am

I'm having issues hosting a server using my public ip and a port that I am sure is forwarded. It gives me failed to create host error, also worth noting that I am pretty sure there isn't a server being hosted on that port. I am able to successfully host a server if I pass "*" or "localhost" to the server address though, however, if I host it with one of these addresses, I am not able to connect a client using my public ip. Do you have any suggestions or thoughts on this?

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 » Tue Jun 13, 2017 10:45 pm

I haven't encountered the issues you are describing so far. I would not expect binding to localhost on the server to work when connecting using the public IP address, because it is explicitly localhost only, even if the client and server are on the same computer. You have to connect with either 127.0.0.1 or localhost in that case. When hosting publicly, binding to "*" or your public IP address directly should work.

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 » Wed Jun 14, 2017 12:43 am

Oh you know I think I might not have explained this very well, I'll try it again.

I have port forwarded the port 27015, I'm sure there is not server running on that port.

On one of my servers I have this code:

Code: Select all

local server = sock.newServer(my_public_ip_here, 27015)
And it gives me the error Failed to create host, is there a server running on this port?

So my problem is hosting a server using my public ip. Works with "localhost" or "*"

Edit: So I asked my friend to host a server using the code I wrote and he is able to connect to himself using his public ip, and I can connect to him fine as well, however, I am not able to connect to myself using my public ip. I have no idea whats going on here.

User avatar
bartbes
Sex machine
Posts: 4943
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post by bartbes » Wed Jun 14, 2017 7:03 am

Did you set up your forward for tcp or udp?

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 » Wed Jun 14, 2017 7:20 pm

I believe that the ports that I've forwarded are for both tcp and udp.

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 » Fri Jun 16, 2017 4:50 am

What's the minimum amount of code that reproduces it? Does it break if you have a main.lua that only calls newServer?

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 16, 2017 4:54 am

Yes, the minimum amount of code needed to cause the error is this:

Code: Select all

local sock = require("lib/networking/sock")

local server = sock.newServer(my_ip_here, 27015)
where my_ip_here is a string that is my public ip address.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests