socketio / socket.io-client-swift

Other
5.21k stars 841 forks source link

How to ignore domain name verification #1407

Open wubangshun opened 2 years ago

wubangshun commented 2 years ago

`import UIKit import SocketIO class ViewController: UIViewController { var manager: SocketManager! var socket: SocketIOClient!

override func viewDidLoad() {
    super.viewDidLoad()
    manager = SocketManager(socketURL: URL(string: "https://60.205.201.205/tc/ws")!, config: [
        .log(true),
        .compress,
        .reconnects(true),
        .path("/tc/ws"),
        .forcePolling(false),
        .forceNew(true),
        .extraHeaders(["Host" : "api.zhongying.com"]),
        .forceWebsockets(true),
        .security(SSLSecurity(usePublicKeys: false))
    ])
    socket = manager.defaultSocket
    socket.on(clientEvent: .connect) {[weak self] data, ack in
        print("connect")
    }
    socket.on(clientEvent: .error) {[weak self] data, ack in
        print("error=>",data)
    }
    socket.connect()
}

}`

print Log: 2022-03-22 16:16:17.754685+0800 SOCKSproxy[13389:231811] LOG SocketIOClient{/}: Adding handler for event: connect 2022-03-22 16:16:17.755489+0800 SOCKSproxy[13389:231811] LOG SocketIOClient{/}: Adding handler for event: error 2022-03-22 16:16:17.757470+0800 SOCKSproxy[13389:231811] LOG SocketIOClient{/}: Handling event: statusChange with data: [connecting, 2] 2022-03-22 16:16:17.758182+0800 SOCKSproxy[13389:231811] LOG SocketIOClient{/}: Joining namespace / 2022-03-22 16:16:17.758608+0800 SOCKSproxy[13389:231811] LOG SocketManager: Tried connecting socket when engine isn't open. Connecting 2022-03-22 16:16:17.759000+0800 SOCKSproxy[13389:231811] LOG SocketManager: Adding engine 2022-03-22 16:16:17.764457+0800 SOCKSproxy[13389:231984] LOG SocketEngine: Starting engine. Server: https://60.205.201.205/tc/ws 2022-03-22 16:16:17.764803+0800 SOCKSproxy[13389:231984] LOG SocketEngine: Handshaking 2022-03-22 16:16:18.276922+0800 SOCKSproxy[13389:231985] CFNetwork SSLHandshake failed (-9807) 2022-03-22 16:16:18.277037+0800 SOCKSproxy[13389:231985] TCP Conn 0x600000328370 SSLHandshake failed (-9807) 2022-03-22 16:16:18.305703+0800 SOCKSproxy[13389:231984] ERROR SocketEngine: The operation couldn’t be completed. (OSStatus error -9807.) 2022-03-22 16:16:18.306634+0800 SOCKSproxy[13389:231811] ERROR SocketManager: The operation couldn’t be completed. (OSStatus error -9807.) 2022-03-22 16:16:18.307950+0800 SOCKSproxy[13389:231811] LOG SocketIOClient{/}: Handling event: error with data: ["The operation couldn’t be completed. (OSStatus error -9807.)"] error=> ["The operation couldn’t be completed. (OSStatus error -9807.)"] 2022-03-22 16:16:18.314501+0800 SOCKSproxy[13389:231811] LOG SocketManager: Starting reconnect 2022-03-22 16:16:18.314900+0800 SOCKSproxy[13389:231811] LOG SocketManager: Trying to reconnect 2022-03-22 16:16:18.315092+0800 SOCKSproxy[13389:231811] LOG SocketIOClient{/}: Handling event: reconnectAttempt with data: [-1] 2022-03-22 16:16:18.315324+0800 SOCKSproxy[13389:231811] LOG SocketManager: Adding engine 2022-03-22 16:16:18.315810+0800 SOCKSproxy[13389:231811] LOG SocketEngine: Engine is being released 2022-03-22 16:16:18.317587+0800 SOCKSproxy[13389:231995] LOG SocketEngine: Starting engine. Server: https://60.205.201.205/tc/ws 2022-03-22 16:16:18.317759+0800 SOCKSproxy[13389:231995] LOG SocketEngine: Handshaking 2022-03-22 16:16:18.319250+0800 SOCKSproxy[13389:231811] LOG SocketManager: Scheduling reconnect in 18.88739711392045s 2022-03-22 16:16:18.412977+0800 SOCKSproxy[13389:232006] CFNetwork SSLHandshake failed (-9807) 2022-03-22 16:16:18.413060+0800 SOCKSproxy[13389:232006] TCP Conn 0x600000324580 SSLHandshake failed (-9807) 2022-03-22 16:16:18.414065+0800 SOCKSproxy[13389:231985] ERROR SocketEngine: The operation couldn’t be completed. (OSStatus error -9807.) 2022-03-22 16:16:18.414418+0800 SOCKSproxy[13389:231811] ERROR SocketManager: The operation couldn’t be completed. (OSStatus error -9807.) 2022-03-22 16:16:18.414626+0800 SOCKSproxy[13389:231811] LOG SocketIOClient{/}: Handling event: error with data: ["The operation couldn’t be completed. (OSStatus error -9807.)"] error=> ["The operation couldn’t be completed. (OSStatus error -9807.)"]

wubangshun commented 2 years ago

Like AFNetworing this setting is ok

`var afn = AFHTTPSessionManager.init() afn.securityPolicy.validatesDomainName = false afn.requestSerializer.setValue("api.zhongying.com", forHTTPHeaderField: "Host") afn.get("https://60.205.201.205/tc/ws") { , in

} failure: { _, err in

}`