在XAMPP上的本地计算机上,一切正常.但是在我将文件上传到服务器后,它给出了这样的错误…
Fatal error: Uncaught exception 'React\Socket\ConnectionException' with message 'Could not bind to tcp://0.0.0.0:8080: Address already in use' in
/home/sites/jemaottest.com/public_html/websocket/vendor/react/socket/src/Server.php:29 Stack trace: #0
/home/sites/jemaottest.com/public_html/websocket/vendor/cboden/ratchet/src/Ratchet/Server/IoServer.php(70): React\Socket\Server->listen(8080, '0.0.0.0') #1
/home/sites/jemaottest.com/public_html/websocket/bin/chat-server.php(17): Ratchet\Server\IoServer::factory(Object(Ratchet\Http\HttpServer), 8080, '0.0.0.0') #2 {main} thrown in
/home/sites/jemaottest.com/public_html/websocket/vendor/react/socket/src/Server.php on line 29
当我运行chat-server.php文件时.
我在Ratchet的故障排除页面上发现了一些内容,
If you want to open Ratchet up (not behind a proxy) set the third parameter of App to ‘0.0.0.0’.
我试过了,但是没有用,
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use MyApp\Chat;
require dirname(__DIR__).'/vendor/autoload.php';
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
)
),
8080,
'0.0.0.0'
);
$server->run();
?>
它仍然给出相同的错误.
我现在应该怎么办?
解决方法:
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
)
),
8282
);
只需更改端口,然后尝试..我的端口更改后工作正常.并且也不要忘记在websocket javascript类中更改端口的端口.
var conn = new WebSocket('ws://yourdomain.com:8282');
标签:ratchet,websocket,socket-io,php
来源: https://codeday.me/bug/20191119/2037980.html