This article introduces you to the code of PHP network programming. Friends who are interested can take a look at
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php
$host = "111.13.100.92" ;
$port = 65530;
set_time_limit(0);
$socket = socket_create(AF_INET,SOCK_STREAM,0) or die ( "不能建立socket链接!\n" );
$result = socket_bind( $socket , $host , $port ) or die ( "不能绑定socket给定的端口\n" );
$result = socket_listen( $socket ,3) or die ( "建立socket连接失败\n" );
$socket_a = socket_accept( $socket ) or die ( "不能接受客户端socket请求\n" );
$input = socket_read( $socket_a ,4096) or die ( "读取客户端输入失败\n" );
$input = trim( $input );
$output = strrev ( $input ). "\n" ;
socket_write( $socket_a , $output , strlen ( $output )) or die ( "不能给客户端返回结果\n" );
socket_close( $socket_a );
socket_close( $socket );
?>
|
Copy after login
Related recommendations:
Page value transfer for getting started with php Analysis of skills
The above is the detailed content of Introduction to php network programming. For more information, please follow other related articles on the PHP Chinese website!