Introduction: This is the PHP socket instance of the detailed page, introduced and php,php, socket, code PHP socket instance related knowledge, skills, experience, and some PHP source code and so on.
class= ' pingjiaf ' frameborder= ' 0 ' src= ' http://biancheng.dnbcw.info/pingjia.php?id=345994 ' scrolling= ' no ' > Below is a PHP Socket Programming example, of course, you can also use Fsockopen
TCP/IP Connection\ n ";/* Get the port for the WWW service. */$service _port = getservbyname (' www ', ' tcp ');/* Get the IP address for the target host. */$address = gethostbyname (' www.example.com ');/* Create a TCP/IP socket. */$socket = Socket_create (Af_inet, Sock_stream, sol_tcp), if ($socket = = = False) {echo "socket_create () Failed:reason: " . Socket_strerror (Socket_last_error ()). "\ n";} else {echo "ok.\n";} echo "Attempting to connect to ' $address ' on port ' $service _port ' ..."; $result = Socket_connect ($socket, $address, $service _port), if ($result = = = False) {echo "Socket_connect () Failed.\nreason: ($result)". Socket_strerror (Socket_last_error ($socket)). "\ n";} else {echo "ok.\n";} $in = "head/http/1.1\r\n"; $in. = "host:www.example.com\r\n"; $in. = "connection:close\r\n\r\n"; $out = "; echo" sending HTTP HEAD request ... "; Socket_write ($socket, $in, strlen ($in)); echo" ok.\n "; echo" Reading response:\n\n "; $buf = ' This is M Y buffer. '; if (false!== ($bytes = Socket_recv ($socket, $buf, 2048, MSg_waitall)) {echo "Read $bytes bytes from Socket_recv (). Closing socket ... ";} else {echo "socket_recv () failed; Reason: ". Socket_strerror (Socket_last_error ($socket)). "\ n";} Socket_close ($socket); Echo $buf. "\ n"; echo "ok.\n\n";? >
Love EE focus on Java Michael Jackson Video station JSON online tool
Http://biancheng.dnbcw.info/php/345994.html Pageno:4