set_time_limit(0);
$server_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($server_socket, ‘127.0.0.1‘, ‘1212‘);
socket_listen($server_socket, 4);
socket_set_nonblock($server_socket);
do{
$msg_socket = socket_accept($server_socket);
if($msg_socket)
{
$buff = socket_read($msg_socket, 1024);
echo "client: ".$buff;
socket_write($msg_socket, $buff);
socket_close($msg_socket);
}
}while(true);
socket_close($server_socket);
2 set_time_limit(0);
3 $client_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
4 socket_connect($client_socket, ‘127.0.0.1‘, 1212);
5 if(isset($argv[1]))
6 {
7 $send = ‘client value ‘.$argv[1];
8 }
9 else
10 {
11 $send = "default";
12 }
13 socket_write($client_socket, $send."\r\n");
14 $response = socket_read($client_socket, 1024);
15 echo "server: ".$response;
16 socket_close($client_socket);