Php 向终端发送bash命令';s在websocket中创建了codeanywhere.com网站的服务器
我想连接到网站的websocket,并向终端创建的服务器发送bash命令 我通过chrome的检查找到url,如下所示:Php 向终端发送bash命令';s在websocket中创建了codeanywhere.com网站的服务器,php,websocket,Php,Websocket,我想连接到网站的websocket,并向终端创建的服务器发送bash命令 我通过chrome的检查找到url,如下所示: wss://terminal.codeanywhere.com/socket.io/?token=a2dc3aaf74fd86450403a32f14134841fb5a32a2c3e38eb8&tabId=2233322-ae3c7ce8-17df-46c9-bf7b-22895ba7b6b7&connectionId=2233322&path=&EIO=3&transp
wss://terminal.codeanywhere.com/socket.io/?token=a2dc3aaf74fd86450403a32f14134841fb5a32a2c3e38eb8&tabId=2233322-ae3c7ce8-17df-46c9-bf7b-22895ba7b6b7&connectionId=2233322&path=&EIO=3&transport=websocket&sid=zH9jTMre4I-HK4E8IyJY
我使用软件包
并编写以下代码:
<?php
require __DIR__ . '/vendor/autoload.php';
$url = 'wss://terminal.codeanywhere.com/socket.io/?token=a2dc3aaf74fd86450403a32f14134841fb5a32a2c3e38eb8&tabId=2233322-ae3c7ce8-17df-46c9-bf7b-22895ba7b6b7&connectionId=2233322&path=&EIO=3&transport=websocket&sid=zH9jTMre4I-HK4E8IyJY';
$headers = [
'Host' => 'terminal.codeanywhere.com',
'Connection' => 'Upgrade',
'Pragma' => 'no-cache',
'Cache-Control' => 'no-cache',
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
'Upgrade' => 'websocket',
'Origin' => 'https://codeanywhere.com',
'Sec-WebSocket-Version' => '13',
'Accept-Encoding' => 'gzip, deflate, br',
'Accept-Language' => 'en-US,en;q=0.9,fa;q=0.8',
'Sec-WebSocket-Key' => 'Ge/uFr0UjX62X84vbsE/Ww==',
'Sec-WebSocket-Extensions' => 'permessage-deflate; client_max_window_bits',
];
$loop = React\EventLoop\Factory::create();
$reactConnector = new \React\Socket\Connector($loop);
$connector = new Ratchet\Client\Connector($loop, $reactConnector);
$connector($url, [], $headers)
->then(function(Ratchet\Client\WebSocket $conn) {
$conn->on('error', function($error) {
echo "Ratchet Pawl error ({$error})\n";
});
$conn->on('message', function(\Ratchet\RFC6455\Messaging\MessageInterface $msg) use ($conn) {
echo "Received: {$msg}\n";
//$conn->close();
});
$conn->on('open', function() {
echo "Connection opened\n";
});
$conn->on('close', function($code = null, $reason = null) {
echo "Connection closed ({$code} - {$reason})\n";
});
//$conn->send('42["data","ls\r"]');
$conn->send('2probe');
}, function(\Exception $e) use ($loop) {
echo "Could not connect: {$e->getMessage()}\n";
$loop->stop();
});
$loop->run();
问题出在哪里?您的解决方案是什么?我会删除所有的标题并进行尝试-您发送的标题会干扰正确的websocket握手。(您的标题指定压缩,Pawl不支持压缩)@mbonneau I忽略了标题的每个项目,然后忽略了标题的所有项目,但无效并返回相同的错误。
Connection closed (1000 - )