在沼泽连接中CFNetwork SSLHandshake失败(-9807)

时间:2017-01-10 11:20:24

标签: swift3 wamp-protocol

import Swamp

class ViewController: UIViewController,SwampSessionDelegate,SwampTransportDelegate {

    let swampTransport = WebSocketSwampTransport(wsEndpoint:  URL(string: "wss://122.166.47.130:8086/ws")!)

    override func viewDidLoad() {
        super.viewDidLoad()
        connect()
    }

    func connect(){
        swampTransport.delegate = self
        let swampSession = SwampSession(realm: "open-realm", transport: swampTransport)
    //    let swampSession = SwampSession(realm: <#T##String#>, transport: <#T##SwampTransport#>, authmethods: <#T##[String]?#>, authid: <#T##String?#>, authrole: , authextra: <#T##[String : Any]?#>)


        swampSession.delegate = self
        swampSession.connect()
    }

    func swampSessionHandleChallenge(_ authMethod: String, extra: [String: Any]) -> String{
        print("swampSessionHandleChallenge")
      return ""
    }

    func swampSessionConnected(_ session: SwampSession, sessionId: Int){
        print("swampSessionConnected")
        session.subscribe("wamp.topic", onSuccess: { subscription in
            print("sssddf")
        }, onError: { details, error in
            print("errorrrr")
        }, onEvent: { details, results, kwResults in
            print("aaaaaa")
        })

    }

    func swampSessionEnded(_ reason: String){
        print("swampSessionEnded= \(reason)")

    }

    public func swampTransportDidConnectWithSerializer(_ serializer: SwampSerializer){
        print("swfdgfsdg")
    }

    public func swampTransportDidDisconnect(_ error: NSError?, reason: String?){
        print("retryw")
    }

    public func swampTransportReceivedData(_ data: Data){
        print("uu7i7")
    }
}

我得到了例外:

  

CFNetwork SSLHandshake失败(-9807)

我认为我添加的领域值是正确的,但我不确定。 Print()用于测试该连接。

1 个答案:

答案 0 :(得分:0)

制作后我解决了 socket.disableSSLCertValidation = true 并将协议设置为 let socket = WebSocket(url:wsEndpoint,protocols:[&#34; protocol_name&#34;])