Just tested your code on a CentOS 6.4 computer. It worked ... I had a "Connection Accepted" from
"http://localhost:8080"
and from another computer on the network I entered
"http://192.168.2.22:8080"
and got "Connection Accepted" on the Linux console. In addition, both the IP address and "localhost" worked with the machine on which the program is running. I am sure this is a network problem.
But try changing the code a bit, just for that ...
Try the following:
changes:
socket_desc = socket(AF_INET , SOCK_STREAM , 0);
in
socket_desc = socket(AF_INET , SOCK_STREAM , IPPROTO_TCP);
add:
close(new_socket);
after
write(new_socket , message , strlen(message));
and again, hell ... add:
memset(&server, 0, sizeof(server));
before using the server structure.
source share