This article introduces you to the Code of PHP network programming, interested friends can see
<?php//echo gethostbyname ("www.baidu.com"); $host = "111.13.100.92"; Set basic information $port = 65530; Set_time_limit (0); Set timeout time//create a socket$socket = Socket_create (af_inet,sock_stream,0) or die ("Cannot establish socket link! \ n ");//bind socket to port $result = Socket_bind ($socket, $host, $port) or Die (" cannot bind socket given port \ n ");//start listening $result = socket_ Listen ($socket, 3) or Die ("failed to establish socket connection \ n"),//Accept connection request, another socket processing communication $socket_a = Socket_accept ($socket) or Die (" Cannot accept client socket request \ n ");//Get client input Request $input = Socket_read ($socket _a,4096) or Die (" read client input failed \ n ");//Empty input character $input = Trim ($ Input),//process the client input and process the result $output = Strrev ($input). " \ n "; Socket_write ($socket _a, $output, strlen ($output)) or Die (" cannot return results to client \ n ");//Close Socketsocket_close ($socket _a); Socket_close ($socket);? >
Related recommendations:
PHP tips for Getting Started page value analysis