如何远程或在服务器上运行 Ratchet? [英] How to run Ratchet remotely or on a server?

查看:37
本文介绍了如何远程或在服务器上运行 Ratchet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的本地机器上的 XAMPP 上一切正常.但是在我将文件上传到服务器后,它给出了这样的错误...

Everything works fine on my local machine on XAMPP. But after I uploaded the files to a server, it gives a error like this...

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 文件时.

when I run the chat-server.php file.

我在 Ratchet 的故障排除页面上发现了一些内容,

I found out something on the troubleshooting page of Ratchet which says,

如果你想打开 Ratchet(不是在代理后面),请将 App 的第三个参数设置为 '0.0.0.0'.

If you want to open Ratchet up (not behind a proxy) set the third parameter of App to '0.0.0.0'.

我试过了,但没有用,

<?php 
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();  
?>

它仍然给出了同样的错误.

it still gave the same error.

我现在该怎么办?

推荐答案

$server = IoServer::factory(
new HttpServer(
    new WsServer(
        new Chat()
    )
),
8282

);

只需更改端口并尝试..更改端口后我的工作正常.并且也不要忘记在 websocket javascript 类中更改端口中的端口.

Just Change the port and try.. mine is works fine after changing my port. And also don't forget to change the port in your port in websocket javascript class too.

var conn = new WebSocket('ws://yourdomain.com:8282');

这篇关于如何远程或在服务器上运行 Ratchet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆