访问 Ratchet Web 套接字请求中的额外参数 [英] Access extra parameters in Ratchet web socket requests

查看:28
本文介绍了访问 Ratchet Web 套接字请求中的额外参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为 PHP 中的 websockets 设置了 Ratchet .它使用 (ws://localhost:8080) 从我的 javascript 客户端正常连接并成功发送/接收消息.但我想传递一些参数,如 (ws://localhost:8080?param1=value).我不知道如何在我的 PHP 脚本中访问 param1.

I've set up Ratchet for websockets in PHP . It is connecting fine from my javascript client using (ws://localhost:8080) and successfully send/receive messages. But I want to pass some params like (ws://localhost:8080?param1=value). I'm not able to figure out how can I access param1 in my PHP script.

如果可能,在 MessageComponentInterface::onOpen(ConnectionInterface $conn) 方法中.

If possible in MessageComponentInterface::onOpen(ConnectionInterface $conn) method.

或者更好:我可以将这些参数与 ConnectionInterface $conn 相关联吗?这样我就可以与他们进行进一步的沟通.

Or better: Can I associate those params with ConnectionInterface $conn. So that I've them for further communication.

我已关注 http://socketo.me/docs/hello-world.

推荐答案

截至 最近更新,您现在可以像这样访问它:

As of a very recent update, you can now access this like so:

function onOpen( ConnectionInterface $conn ) {
   $querystring = $conn->WebSocket->request->getQuery();
}

我实际上只是自己遇到了这个问题.对此进行了测试,效果很好.

I actually just ran into this issue myself. Tested this and it's working perfectly.

这篇关于访问 Ratchet Web 套接字请求中的额外参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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