zxc0324
zxc0324
2016-02-24 07:48

websocket client执行socket_write 就断开连接

  • websocket
  • socket

php 充当websocket客户端,模拟向服务器端发消息,但是一执行socket_write连接就丢失了。
是因为php是短连接吗?我在服务端有监控发送的消息,没有收到消息。

代码:
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, '********', ***);
echo $result."\n";
echo "Send Command..........\n";
$msg = 'test msg';
socket_write($socket, $msg, strlen($msg));
echo "OK\n";
echo "Reading Backinformatin:\n\n";
while ($out = socket_read($socket, 2048)) {
echo $out." out\n";
}
echo "Close socket........\n";
//socket_close($socket);
echo "OK,He He.\n\n";

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答