Elephant.io 服务器错误 Php(尝试与服务器建立连接时发生错误)

Elephant.io server error with Php( An error occurred while trying to establish a connection to the server)

我有一个问题要问你,我在 socket.ioelephant.io php application,但是我已经处理了将近2天的elephant.io错误。我做错了什么吗?以下是我得到的错误和代码。

我的错误 enter image description here

我的INDEX.PHP

require __DIR__ . '/vendor/autoload.php';

use ElephantIO\Client;
use ElephantIO\Engine\SocketIO\Version2X;

$client = new Client(new Version2X('http://localhost:9090'));
$client->initialize();
$client->emit('send-message', [
    'name' => 'john',
    'surname' => 'doe'
]);
$client->close();

我的APP.JS

const server = require('http').createServer();
const io = require('socket.io')(server,{
    cors: {
        origin: "*",
    }
});
io.on('connection',function (socket){
    console.log('connected');
   socket.on('send-message',function (data){
       console.log(data);
       io.emit('message',data);
   })
   socket.on('disconnect',function (){
       console.log('disconnected')
   })
})
server.listen(9090);

我的SOCKET.HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.2.0/socket.io.js" 
integrity="sha512-WL6WGKMPBiM9PnHRYIn5YEtq0Z8XP4fkVb4qy7PP4vhmYQErJ/dySyXuFIMDf1eEYCXCrQrMJfkNwKc9gsjTjA==" 
crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script>
var socket = io('http://localhost:9090');
socket.on('message',function (data){
    console.log(data);
});
socket.emit('send-message',{
    "name":"johnHTML",
    "surname": "doeHTML"
});
</script>
</body>
</html>

我遇到过一次这个错误。我像你一样搜索过,但找不到。我尝试了很多不同的方法,其中 none 行得通。作为最后的手段,我将 "socket.io" 库的版本更改为 2.2.0 并且它起作用了。你应该试试这个

您可以使用这个 elephant.io 的更新代码而无需降级您的套接字版本。支持socket版本大于3

https://github.com/tohenk/elephant.io