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

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

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

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?

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

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

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.

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

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

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

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

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

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?

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

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

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.

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

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

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.

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

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

Did you set up your forward for tcp or udp?

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

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

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

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

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

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

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

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

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.

### Who is online

Users browsing this forum: No registered users and 7 guests