我的客户端脚本和服务器之间没有WebSocket连接,它在我当前的环境中运行得很好。同时,我也遵循这个链接。
下面是一个服务器脚本,它初始化WebSocket服务器并让客户端连接到了8080端口。
public function run()
{
$loop = Factory::create();
$pusher = new Pusher;
$context = new 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 Server('0.0.0.0:8080', $loop); // Binding to 0.0.0.0 means remotes can connect
$webServer = new IoServer(
new HttpServer(
new WsServer(
new WampServer(
$pusher
)
)
),
$webSock
);
$loop->run();
这是客户端脚本:
var conn = new ab.Session('ws://localhost:8080',
function() {
/* subscribe to following topics */
conn.subscribe('new_order', function(topic, data) ..
同样,这在本地设置中运行良好。
还要注意的是,我的应用程序是使用来自docker容器的指定端口承载的。
http://192.168.12.52:8094/xyz/new/....
我还尝试在客户端脚本中指定IP:
var conn = new ab.Session('ws://192.168.12.52:8080',
function() {
/* subscribe to following topics */
conn.subscribe('new_order', function(topic, data) ...
在这种情况下,我会得到以下错误:
WebSocket connection to 'ws://192.168.11.32:8080/' failed: Error during WebSocket handshake: Unexpected response code: 403
这里缺少什么?
</div>