Closed kevin19a closed 4 years ago
复现代码,saber版本,swoole版本发一下。
public function test1(){ $websocket = SaberGM::websocket('ws://123.207.136.134:9010/ajaxchattest'); $i = 5; while ($i) { // echo $websocket->recv() . "\n" $ret = $websocket->recv(); var_dump($ret); $websocket->push("hello $i!"); $i--; co::sleep(0.5); } }
上面是代码
复现代码,saber版本,swoole版本发一下。
"require": { "php": ">=7.1.0", "topthink/framework": "^6.0.0", "topthink/think-orm": "^2.0", "topthink/think-swoole": "^3.0", "swlib/saber": "^1.0" },
Swoole版本呢 php --ri swoole
Swoole版本呢
php --ri swoole
Swoole => enabled Author => Swoole Team team@swoole.com Version => 4.5.3 Built => Aug 31 2020 19:15:51 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.0.2k-fips 26 Jan 2017 http2 => enabled pcre => enabled zlib => 1.2.7 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled mysqlnd => enabled async_redis => enabled
Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608
我这边测试是握手请求被拒绝了
我这边测试是握手请求被拒绝了
http://coolaf.com/tool/chattest 我是测试内网的。找了个公网的。是因为跨域名了?
你直接用Swoole的这样试下呢?
Co\run(function () {
$client = new Swoole\Coroutine\Http\Client("127.0.0.1", 9501);
$ret = $client->upgrade("/");
if ($ret) {
while(true) {
$client->push("hello");
var_dump($client->recv());
co::sleep(0.1);
}
}
});
你发的代码ip能访问,网页版测试可以连通,代码就不行
你直接用Swoole的这样试下呢?
Co\run(function () { $client = new Swoole\Coroutine\Http\Client("127.0.0.1", 9501); $ret = $client->upgrade("/"); if ($ret) { while(true) { $client->push("hello"); var_dump($client->recv()); co::sleep(0.1); } } });
你发的代码ip能访问,网页版测试可以连通,代码就不行
所以就很尴尬啊~我项目是基于tp6.0做的。就算直接 swoole能通。。我也要解决这里面为啥不通。。。
握手请求被拒绝了,主干代码修了,原来的获取不到http code。
HTTP 0 Unknown: Websocket upgrade failed by [Success]. 有没有也遇到过这个问题的?