套接字不会与红蜘蛛

时间:2016-05-06 13:28:57

标签: ios swift sockets connect

我正在使用红蜘蛛打开一个websocket。问题是它不能在localhost或服务器上连接。

var socket = WebSocket(url: NSURL(string: "ws://localhost:8080/")!)
self.socket.voipEnabled = true;
        socket.delegate = self
        socket.connect()
 func websocketDidConnect(ws: WebSocket) {
        print("websocket is connected")
    }

    func websocketDidDisconnect(ws: WebSocket, error: NSError?) {
        print("websocket is disconnected: \(error?.localizedDescription)")
    }

    func websocketDidReceiveMessage(ws: WebSocket, text: String) {
        print("Received text: \(text)")
    }

    func websocketDidReceiveData(ws: WebSocket, data: NSData) {
        print("Received data: \(data.length)")
    }

    func websocketDidReceivePong(socket: WebSocket) {
        print("Got pong!")
    }

    @IBAction func writeText(sender: UIBarButtonItem) {
        socket.writeString("hello there!")
    }

1 个答案:

答案 0 :(得分:0)

一旦我添加了self.socket.selfSignedSSL = true;

,它就开始连接了