$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_bind($socket,'0.0.0.0',6666);
while(true){
socket_listen($socket);
$sock = socket_accept($socket);
$res = socket_read($sock,2048);
echo $res.PHP_EOL;
socket_write($sock,'收到客户端消息: '.$res);
}
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_connect($socket,'0.0.0.0',6666);
$msg = 'hlllo server';
socket_write($socket,$msg);
$res = socket_read($socket,2048);
echo $res;
来源:oschina
链接:https://my.oschina.net/u/4409444/blog/3425543