如何将 SocketRocket 与 socket.io 一起使用?
新的 iOS websocket 库 SocketRocket 看起来真的很棒,聊天示例项目也很不错。示例聊天服务器是用 Python 编写的,但我对此一无所知。我对node.js 上的socket.io 有点熟悉,更喜欢尝试javascript。我尝试将 SocketRocket TestChat 模拟器应用程序连接到 node.js(6.10) socket.io(0.8.7),但连接被拒绝。 (另外,我也不是节点专家,所以这可能是一个愚蠢的问题)。
在最近对 SO 问题 的回答中,mikelikespie对 op 说:“我建议更新你的堆栈以使用我们刚刚发布的 iOS WebSocket 库。”
这到底是什么意思?让 SocketRocket 库与节点 socket.io 服务器通信需要什么?任何示例代码或建议都将不胜感激。
The new iOS websocket library, SocketRocket, looks really awesome, and the chat example project is really sweet. The example chat server is written in Python, of which I know none. I'm slightly familiar with socket.io on node.js and prefer to try javascript. I tried connecting the SocketRocket TestChat simulator app to the node.js(6.10) socket.io(0.8.7) but the connection was refused. (Also, I'm not a node expert either, so this may be a silly question).
In a recent answer to an SO question, mikelikespie said to op: "I suggest updating your stack to use the iOS WebSocket library we just released."
What does that mean exactly? What is necessary to get the SocketRocket library to talk to a node socket.io server? Any sample code or suggestions are greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,socket.io 有自己的基于传输协议(例如 websockets 或长轮询)的协议,那么 SocketRocket 只是一个 websocket 库,仅此而已。 Socket.io 也有一些身份验证,因此无法通过普通的 Web 套接字使用它。我建议你使用一个 websocket 服务器,仅此而已。例如 ws ,应该兼容。还有其他库,但是,我相信
ws
目前正在积极开发,并且比其他库更新。你也可以让你的客户端socket.io兼容,但我认为这是不必要的。这是它的规格:https://github.com/LearnBoost/socket.io-spec
希望我有所帮助。
Well you socket.io has it's own protocol built on transport protocols such as websockets, or long polling, well SocketRocket is just a websocket library, no more. Socket.io also has some authentication, so it's not possible to use it, with normal web sockets. What I suggest you to use is a just websocket server, no more than that. Such as ws, which should compatible. There are other libraries, but,
ws
I believe is actively developed at the moment, and newer than others.You can also make your clientside socket.io compatible, but I think its uneeded. Here's the specs for it: https://github.com/LearnBoost/socket.io-spec
Hope I helped.
GitHub 上的 socket.IO-objc 看起来是一个成熟的 Socket.IO / Objective C 库
它使用 SocketRocket 来处理 websocket 连接。
这将使您拥有一个支持旧版浏览器(降级为长轮询等)的套接字服务器,并且仍然可以通过 SocketRocket 访问您的 iOS 应用程序。
socket.IO-objc on GitHub looks to be a mature Socket.IO / Objective C Library
It uses SocketRocket to handle the websocket connections.
This will allow you to have a socket server that supports older browsers (degrades to long-polling etc.) and is still accessable to your iOS app via SocketRocket.
我刚刚使用 这个库 在 Node.JS 服务器和 iOS 应用程序之间实现了主动套接字连接。我使用这个是因为 Socket.IO-ObjC 上的自述文件说
但我总是想使用最新版本的一切。因此,如果您想使用 Socket.IO v1.0,您可以使用上面几行提供的链接上的那个。
I have just implemented an active socket connection between a Node.JS server, and an iOS application, using this library. I used this one because the README on Socket.IO-ObjC says
but I always want to use the latest version for everything. So if you want to use Socket.IO v1.0, you can use the one on the link provided few line above.