php - Ratchet PHP : How to mention host name?

标签 php websocket ratchet

根据代码,我这样做了:

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

我想保持主机可配置,因为我还需要将该值传递给 JS 客户端。

最佳答案

如果您使用上面提供的代码,则主机始终设置为您的服务器链接到的任何内容。

如果 example.com 链接到您的端口 80
然后 example.com:8008 将链接到您在服务器上的端口 8080

如果您想强制客户端使用某个主机名,那么应该通过套接字本身的 subscribe 函数来完成。

如果您没有 DNS 名称而只有 IP 地址:123.123.123.123
然后 123.123.123.123:8080 将链接到您的 websocket。

如果这是您的要求,或者您需要更多信息,请告诉我。

关于php - Ratchet PHP : How to mention host name?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36642846/

相关文章:

javascript - 使用Ajax、PHP上传PDF文件到MYSQL数据库

javascript - Codeigniter csrf ajax错误

php - 获取 WooCommerce 属性值 (url) 以将其用作 href 链接

primefaces - Atmosphere 错误 : Error during WebSocket handshake: Unexpected response code: 501

php - 使用哪个 Ratchet 组件

php - 如何使用 ReactPHP 和 Ratchet 在同一端口上运行 WebSocket 和 HTTP Server?

php - 无法使用 Jquery 获取 JSON 值

Node.js Express websocket 不向所有连接的客户端广播

scala - Play Framework Websocket 服务器不处理来自 netty 客户端的 Ping 帧

php - Ratchet ,插入集成,不工作