【问题标题】:Unitt websocket library cannot ope the socket on iOSUnity websocket 库无法在 iOS 上打开套接字
【发布时间】:2012-02-22 20:48:26
【问题描述】:

我研究了如何将 Web Socket 功能集成到 iOS 应用程序中并遇到了一些问题。一切都按照教程(http://code.google.com/p/unitt/wiki/UnittWebSocketClient)做,但得到一些奇怪的错误:

Error Domain=NSPOSIXErrorDomain Code=61 "The operation couldn’t be completed. Connection refused"

问题可能是由什么引起的?这是我的项目https://github.com/artem888/WebSocketTest

我也尝试使用 Socket Rocket(https://github.com/square/SocketRocket),但是我根本没有收到委托消息。这里是项目源https://github.com/artem888/WebSocketTest2

感谢您的回答,因为我在 iOS 上的 WebSocket 介绍之旅非常尴尬:D

阿尔乔姆

【问题讨论】:

    标签: iphone ios web-services


    【解决方案1】:

    对于 Socket Rocket,问题在于 SRWebSocket 必须是 iVar,否则它不会收到任何委托消息。

    @implementation TCViewController {
        SRWebSocket *_webSocket;
    }
    

    然后像这样初始化:

        _webSocket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"ws://localhost:9000/chat"]]];
        _webSocket.delegate = self;
    
        [_webSocket open];
    

    仍然感谢有关 Unitt 的回答。

    【讨论】:

    • 你能给我指出一些使用 Unitt 库的示例代码吗?我很乐意提供帮助,但我找不到您正在使用它的任何代码。
    猜你喜欢
    • 2013-09-11
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 2022-06-13
    • 2016-02-04
    • 1970-01-01
    • 2016-03-23
    • 1970-01-01
    相关资源
    最近更新 更多