socket能监听到数据 但是发送不出去呢
error_reporting(E_ALL);
set_time_limit(0);
//ob_implicit_flush();
$ip = 'xxx';
$port = 6666;
//创建端口
if( ($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
echo "socket_create() failed :reason:" . socket_strerror(socket_last_error()) . "n";
}
//绑定
if (socket_bind($socket, $ip, $port) === false) {
echo "socket_bind() failed :reason:" . socket_strerror(socket_last_error($socket)) . "n";
}
//监听
if (socket_listen($socket, 5) === false) {
echo "socket_bind() failed :reason:" . socket_strerror(socket_last_error($socket)) . "n";
}
do {
//得到一个链接
if (($msgsocket = socket_accept($socket)) === false) {
echo "socket_accepty() failed :reason:".socket_strerror(socket_last_error($socket)) . "n";
break;
}
//welcome 发送到客户端
$msg ="server send:welcome";
socket_write($msgsocket, $msg, strlen($msg));
echo 'read client messagen';
$buf = socket_read($msgsocket, 8192);
$talkback = "$bufn";
echo $talkback;
if (false === socket_write($msgsocket, $talkback, strlen($talkback))) {
echo "socket_write() failed reason:" . socket_strerror(socket_last_error($socket)) ."n";
} else {
echo 'send success';
}
socket_close($msgsocket);
} while(true);
//关闭socket
socket_close($socket);
?>
{"msghead":{"msgid":26,"uid":12502559,"rid":"841049","transmode":1},"msgbody":{"srcuid":12502559,"dstuid":12502559,"rid":"841049","gid":"1024","giftname":"u6211u9519u4e86","count":"1","time":1413386346,"type":2,"nickname":"jinkang","wealth":"451350","credit":"355311","identity":"2","star":1,"date":"23:19"}} 能监听到数据 但是服务端发送的 怎么客户端接收不到呢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
引用来自“domrr”的评论
为啥不用开源的socket框架呢?自己写 socket
daemon容易挂
为啥不用开源的socket框架呢?自己写 socket
daemon容易挂