pusher / NWWebSocket

A WebSocket client written in Swift, using the Network framework from Apple.
MIT License
123 stars 25 forks source link

How to solve SNI (Server Name Indication) #34

Closed HuYuee closed 2 years ago

HuYuee commented 2 years ago

hello,how to solve SNI (Server Name Indication) ?can you give me some demo or readme

benw-pusher commented 2 years ago

Hi, Could you share a bit more about the specific issue you are encountering?

HuYuee commented 2 years ago

thx, i solved this problem. i use setAdditionalHeaders and sec_protocol_options_set_tls_server_name. code like this:

      let options = NWProtocolTCP.Options()

      options.connectionTimeout = 15

      let tlsOptions = NWProtocolTLS.Options()

      sec_protocol_options_set_tls_server_name(tlsOptions.securityProtocolOptions,"your domain")

      let protocolOptions = NWProtocolWebSocket.Options()

      protocolOptions.setAdditionalHeaders([("host", "your domain")])

      let parameters = NWParameters(tls: tlsOptions, tcp: options)

      parameters.defaultProtocolStack.applicationProtocols.insert(protocolOptions, at: 0)

      connection = NWConnection(to: NWEndpoint.url(url), using: parameters)
benw-pusher commented 2 years ago

Thanks for coming back, glad you were able to solve.