首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >棘轮-如何防止其他网站连接到我的websocket服务器?

棘轮-如何防止其他网站连接到我的websocket服务器?
EN

Stack Overflow用户
提问于 2019-08-28 05:17:55
回答 1查看 267关注 0票数 2

http://socketo.me/docs/origin中有一个页面在谈论它,但它完全不清楚如何实现它。

这是我当前的代码(来自http://socketo.me/docs/push的教程):

代码语言:javascript
代码运行次数:0
运行
复制
<?php
require dirname(__DIR__) . '/vendor/autoload.php';

$loop   = React\EventLoop\Factory::create();
$pusher = new MyApp\Pusher;

// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onBlogEntry'));

// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server('0.0.0.0:8080', $loop); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
    new Ratchet\Http\HttpServer(
        new Ratchet\WebSocket\WsServer(
            new Ratchet\Wamp\WampServer(
                $pusher
            )
        )
    ),
    $webSock
);

$loop->run();

按照http://socketo.me/docs/origin的教程,我应该将变量$checkedApp添加到类HttpServer的构造函数中。我检查了这个类的souce code,它在__constructor()中只使用了一个参数,正如您所看到的,我已经向这个构造函数传递了一个值,它是WsServer类的一个实例。此外,类MyHttpApp也不存在。

EN

回答 1

Stack Overflow用户

发布于 2019-08-29 02:31:23

我在源代码中搜索了一下,找到了位于https://github.com/ratchetphp/Ratchet/blob/master/src/Ratchet/App.php的文件App.php,要实现OriginChecker,我只需要将变量$webServer的值更改为以下值:

代码语言:javascript
代码运行次数:0
运行
复制
$webServer = new Ratchet\Server\IoServer(
    new Ratchet\Http\HttpServer(
        new Ratchet\Http\OriginCheck(
            new Ratchet\WebSocket\WsServer(
                new Ratchet\Wamp\WampServer(
                    $pusher
                )
            ),
            array('mydomain.com') //this is the only domain that can connect to the websocket
        )
    ),
    $webSock
);
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57682382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档