sockets - Miniature PHP webserver not accepting connections on anything other than 127.0.0.1:80 -
I created a small 'web server' which gives a message to any request sent on port 80. I can connect through it but when I try to connect it to my real IP address, nothing comes up.
Code:
# config $ conn_ip = "127.0.0.1"; // possibly $ conn_port = 80 localhost; // $ conn_max = 5 port for hosting 'server'; // maximum connection # end config $ output = 'blah' to accept; # Ready php script set_time_limit (0); Ob_implicit_flush (true); # End # Setup socket $ server = socket_create (AF_INET, SOCK_STREAM, SOL_TCP); Socket_bind ($ server, $ conn_ip, $ conn_port); Socket_listen ($ server, $ conn_max); # End print "listening on port 80 ... \ n \ n"; # Loop while (true) {if ($ new_sock = socket_accept ($ server))! == faucet) {print ("The connection was found ... \ n"); Socket_write ($ new_sock, $ product, strlen ($ product)); Socket_close ($ new_sock); }} # End? & Gt;
What am I doing wrong here?
Change this line
$ conn_ip = "127.0.0.1 "; // perhaps from local host
to
$ conn_ip = 0; 127.0.0.1 means that your "webserver" will listen to the connection only on 127.0.0.1 (localhost) 0 means that your "webserver" will listen to every IP on your computer. >
Comments
Post a Comment