PHP socket how to test 
This post was last edited by d6965921d on 2014-07-13 09:57:41 
 
 Error_reporting (E_all);
Set_time_limit (0);
Ob_implicit_flush ();
$address = ' 127.0.0.1 ';
$port = 10005;
Creating ports
if ($sock = Socket_create (Af_inet, sock_stream, sol_tcp) = = = = False) {
echo "Socket_create () Failed:reason:". Socket_strerror (Socket_last_error ()). "\ n";
}
Binding
if (Socket_bind ($sock, $address, $port) = = = = False) {
echo "Socket_bind () Failed:reason:". Socket_strerror (Socket_last_error ($sock)). "\ n";
}
Listening
if (Socket_listen ($sock, 5) = = = = False) {
echo "Socket_bind () Failed:reason:". Socket_strerror (Socket_last_error ($sock)). "\ n";
}
do {
Get a link
if ($msgsock = socket_accept ($sock)) = = = = False) {
echo "Socket_accepty () Failed:reason:". Socket_strerror (Socket_last_error ($sock)). " \ n ";
Break
}
Welcome Send to Client
$msg = "Server Send:welcome
";
Socket_write ($msgsock, $msg, strlen ($msg));
Echo ' read client message\n ';
$buf = Socket_read ($msgsock, 8192);
$talkback = "received message: $BUF \ n";
Echo $talkback;
if (false = = = Socket_write ($msgsock, $talkback, strlen ($talkback))) {
echo "Socket_write () failed reason:". Socket_strerror (Socket_last_error ($sock)). " \ n ";
} else {
Echo ' send success ';
}
Socket_close ($msgsock);
} while (true);
Close socket
Socket_close ($sock);
?>
 
How does this code work? I opened the page and I couldn't open it. 
How do I test the effect of this socket I've written? I would like to test the successful re-write the socket client before the HTTP direct input URL will know ... The socket really doesn't know how to test it. 
------Solution-------------------- 
Try a different port.