xcode 在 Objective-C 中使用 WebSocket

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8235616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:32:05  来源:igfitidea点击:

Using WebSockets in Objective-C

iphoneobjective-ciosxcodewebsocket

提问by John Smith

I have tried, unsuccessfully, to use websockets in objective-c with the following two libraries:

我曾尝试在objective-c 中使用websockets 和以下两个库,但没有成功:

http://code.google.com/p/unitt/wiki/UnittWebSocketClient

http://code.google.com/p/unitt/wiki/UnittWebSocketClient

https://github.com/zootreeves/iOS-WebSockets

https://github.com/zootreeves/iOS-WebSockets

In both cases I was unable to establish even a basic connection to a server (runnning on localhost). I was wondering if someone could please provide or point me in the direction of some code that will just simply connect to a server via a websocket and/or perform a handshake.

在这两种情况下,我甚至无法建立到服务器的基本连接(在本地主机上运行)。我想知道是否有人可以提供或指向我一些代码的方向,这些代码只需通过 websocket 连接到服务器和/或执行握手。

Ideally, it would be nice if the code could use one of the above libraries, but at this point I'm open to anything that'd work.

理想情况下,如果代码可以使用上述库之一,那就太好了,但在这一点上,我愿意接受任何可行的方法。

I've posted about some issues with UnitT beore but I haven't received any feedback so I'm not sure exactly what step I'm messing up on. Appreciate any help, thanks!

我已经发布了有关 UnitT beore 的一些问题,但我没有收到任何反馈,所以我不确定我到底在搞什么步骤。感谢任何帮助,谢谢!

回答by mikelikespie

We just released SocketRocket. It supports the latest standard, RFC 6455, which neither ZTWebSocket, nor Unitt does. No CocoaAsyncSocket needed to boot.

我们刚刚发布了SocketRocket。它支持最新的标准RFC 6455,ZTWebSocket 和 Unitt 都不支持。无需 CocoaAsyncSocket 启动。

Also, libPusher is experimentingwith SocketRocket too.

此外,libPusher 也在试验SocketRocket。

回答by leggetter

The libPusherlibrary uses the ZTWebSocketobject. And we have a number of clients who've developed iOS applications against our service. So, the ZTWebSocket object works and should be a good starting point. The libPusher library would be a good reference for usage.

libPusher库使用ZTWebSocket对象。我们有许多客户针对我们的服务开发了 iOS 应用程序。因此,ZTWebSocket 对象有效并且应该是一个很好的起点。libPusher 库将是一个很好的使用参考。

回答by Josh Morris

The key to making UnitT work is to find out what version of the specification is your server running. Then you use the correct version for the client. The latest (rev17) of the specification FINALLY allows for multiple versions and having the server send back an appropriate response, but none of the prior versions do. Therefore, you may not receive a meaningful error from the server, just a disconnection. Do you know what version your server is running?

使 UnitT 工作的关键是找出您的服务器正在运行的规范版本。然后您为客户端使用正确的版本。规范的最新版本 (rev17) 最终允许多个版本并让服务器发回适当的响应,但之前的版本都没有。因此,您可能不会从服务器收到有意义的错误,只是断开连接。你知道你的服务器运行的是什么版本吗?