1
I have a Debian server machine at home with NGINX. Right now it is only serving the default index.html that installs along with nginx. I got myself a hostname in Dynu and got TLS certificates with Let's Encrypt
I can perfectly access my default nginx website on the web browser using my hostname and everything is working fine.
But I need to implement a simple server socket in C in this Debian server listening on port 8080 and connect to it with a client socket in C from any a computer via the internet.
My problem here is that despite having already forwarded port 8080 in my home router and having added port 8888 to the Debian server firewall (sudo ufw allow 8888/tcp
and sudo ufw allow 8888/udp
), I still can't connect to the server socket.
If I run both server and client socket programs on the same machine, they work just fine when connecting the client to localhost
so I know the code is working fine. The problem is when I run the server socket program in the Debian server and the client socket program in my laptop they don't connect whether I use the Debian local address or the dynu hostname.
When I run the client it finishes with the error Connection refused
and the server socket program doesn't even blink, it just stays on Waiting for connection on port 8888.
I mentioned at the beginning the nginx, the hostname, and the certificates because I don't know if this could be conflicting with a nginx-independent c server socket, I mean, I don't know if that is a restriction of nginx. I don't think it is because I'm using a port different than the ones nginx is configured with, but I'm not sure. I have even sudo systemctl stop nginx
'ed the nginx server but that doesn't help.
What am I missing?
UPDATE: ok, I ran my server socket and put it to listen, then I ran netstat -ntlp
and now I can see my server socket application as:
tcp 0 0 127.0.0.1:8888 0.0.0.0:* LISTEN 8959/socket-server/
I had to change to port 8888 because port 8080 is being used by "WWW Cache" (whatever that is), but the client still doesn't connect.
My socket server is binding to an address obtained by getaddrinfo(NULL, port, &hints, &server_info)
Is your server binding to localhost only? What does
netstat -ntlp
say about port 8080? – filbranden – 2020-02-25T23:30:29.960@filbranden holy molly! It is not there! I just ran that command and I don't see 8080. but if I run
sudo ufw allow 8080
I can see it. Why could this be? – m4l490n – 2020-02-25T23:42:05.480ufw will simply say that you have a rule allowing connections on that port... But if there's nothing listening there, you won't be able to connect. Are you sure your server is listening on that port? Is it really a TCP server? Can you use something like
nc
ortelnet
to test to connect to it locally? – filbranden – 2020-02-25T23:59:11.6631ok, I ran my server socket and put it to listen, then I ran
netstat -ntlp
and now I can see my server socket application astcp 0 0 127.0.0.1:8888 0.0.0.0:* LISTEN 8959/socket-server/
. I had to change to port 8888 because port 8080 is being used byWWW Cache
(whatever that is), but the client still doesn't connect – m4l490n – 2020-02-26T00:16:35.677