C socket program as web server to run in cloud, not receiving any response from browser
Just tested your code on a CentOS 6.4 machine. It worked... I had "Connection Accepted" from
"http://localhost:8080"
and from another machine on the network, I entered
"http://192.168.2.22:8080"
and got a "Connection Accepted" on the Linux console. Also, both IP address and "localhost" worked from the machine running the program. I'm pretty sure it's a network issue.
But try changing your code a bit just for the heck of it...
Try this:
change:
socket_desc = socket(AF_INET , SOCK_STREAM , 0);
to:
socket_desc = socket(AF_INET , SOCK_STREAM , IPPROTO_TCP);
add:
close(new_socket);
after:
write(new_socket , message , strlen(message));
and once again, for the heck of it...add:
memset(&server, 0, sizeof(server));
before you use your server struct.
you check the firewall settings of running host.
if it is linux, use command
netstat -atnp
- to see your program is opened the desired port (8080) or not.
service iptables stop
- to stop firewall in old versions
systemctl stop firewalld
- to stop firewall in latest versions
enable firewall again once you completed testing your program by replacing stop
by start
.
or allow TCP port 8080 in firewall settings if you want to permanently use that port