workerman作为wss客户端提示Sec-WebSocket-Accept not found

0

 
问题同:https://wenda.workerman.net/question/3379 ,但该哥们说找到是自己的问题了,我这边还是有问题,麻烦各位大佬帮忙看看问题所在.
 
在浏览器端可连接,原ws地址是:wss://ws.coincap.io/prices?assets=bitcoin,ethereum,ws://ws.coincap.io:443/prices?assets=bitcoin,ethereum,这种URL形式也试过的.


require_once __DIR__.'/vendor/autoload.php';
use Workerman\Connection\AsyncTcpConnection;
use Workerman\Worker;

$worker = new Worker('text://0.0.0.0:6161');

$worker->onWorkerStart = function() {
// 以websocket协议连接远程websocket服务器
/*$context = ;
$con = new AsyncTcpConnection("ws://ws.coincap.io/prices?assets=bitcoin,ethereum", $context);*/
/*$con = new AsyncTcpConnection("ws://ws.coincap.io/prices?assets=bitcoin,ethereum");
$con->transport = 'sslv3';*/
$con = new AsyncTcpConnection("ws://ws.coincap.io:443/prices?assets=bitcoin,ethereum");
//$con->transport = 'ssl';
// 注册连接上后的事件
$con->onConnect = function($con){
echo "connected\n";
};
$con->onWebSocketConnect = function($con, $http_buffer){
echo $http_buffer;
};
// 远程websocket服务器发来消息时
$con->onMessage = function($con, $data){
echo "recv: $data\n";
};
// 连接上发生错误时,一般是连接远程websocket服务器失败错误
$con->onError = function($con, $code, $msg){
echo "error: $msg\n";
};
// 当连接远程websocket服务器的连接断开时
$con->onClose = function($con){
echo "connection closed\n";
$con->reconnect(1);
};
// 设置好以上各种回调后,执行连接操作
$con->connect();
};

Worker::runAll();

报错信息为:


Press Ctrl+C to stop. Start success.
connected
Sec-WebSocket-Accept not found. Header:
HTTP/1.1 400 Bad Request
Server: cloudflare
Date: Sat, 08 Dec 2018 14:38:41 GMT
Content-Type: text/html
Content-Length: 269
Connection: close
CF-RAY: -
connection closed

脚本执行方式:php client.php start

已邀请:

rockman1107

赞同来自:

找到问题所在了,原来是端口号443跟$con->transport = 'ssl' 要同时设置,估计犯我这错的人比较少,汗颜

pgzgn

赞同来自:

老哥能帮忙看一看么,xhell已经显示成功了,但是没有任何的输出,

中榜

赞同来自:

老哥,为什么我的yesi这样?
 

dignfei - 丹妮

赞同来自:

哥,我的也是这样,请问怎么设置?


// 以websocket协议连接远程websocket服务器
$wssUrl = 'ws://tts-api.xfyun.cn:443/v2/tts?authorization=YXBpX2tleT0iNGMzZDc2MjBlOTI3MmYyNmI1OTY0ZWM0ZmI0MGVkYjQiLGFsZ29yaXRobT0iaG1hYy1zaGEyNTYiLGhlYWRlcnM9Imhvc3QgZGF0ZSByZXF1ZXN0LWxpbmUiLHNpZ25hdHVyZT0iRWtFeENmRVlmVVQ3VVI5OEVuTEdoR1U2YmNqQ0RnV3QvdEVUSTJobHdJZz0i&date=Sat, 07 Nov 2020 13:32:33 GMT&host=tts-api.xfyun.cn';
$ws_connection = new AsyncTcpConnection($wssUrl);
// 设置以ssl加密方式访问,使之成为wss
$ws_connection->transport = 'sslv3';
// 连上后发送hello字符串
$ws_connection->onConnect = function($connection) use($frame){
$connection->send(json_encode($frame));
};
// 远程websocket服务器发来消息时
$ws_connection->onMessage = function($connection, $data){
echo "recv: $data\n";
};
// 连接上发生错误时,一般是连接远程websocket服务器失败错误
$ws_connection->onError = function($connection, $code, $msg){
echo "error: $msg\n";
};
// 当连接远程websocket服务器的连接断开时
$ws_connection->onClose = function($connection){
echo "connection closed\n";
};
// 设置好以上各种回调后,执行连接操作
$ws_connection->connect();


返回:
Sec-WebSocket-Accept not found. Header:
HTTP/1.1 400 Bad Request
Date: Sat, 07 Nov 2020 13:31:17 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 220
Connection: close
Server: kong/1.3.0
connection closed

要回复问题请先登录注册