SocketIOException: Unexpected client connectivity error

The following exception:

SocketIOException: Unexpected handshake error in client (OS Error: errno = -12268) #0 _SecureFilterImpl.handshake (dart:io-patch:849:8) #1 _SecureSocket._secureHandshake (dart:io:7382:28) #2 _SecureSocket._secureConnectHandler._secureConnectHandler (dart:io:7294:21) #3 _Socket._updateOutHandler.firstWriteHandler (dart:io-patch:773:64) #4 _SocketBase._multiplex (dart:io-patch:408:26) #5 _SocketBase._sendToEventHandler.<anonymous closure> (dart:io-patch:509:20) #6 _ReceivePortImpl._handleMessage (dart:isolate-patch:37:92) 

obtained from the following code:

 String url = "https://www.google.com"; HttpClient client = new HttpClient(); HttpClientConnection conn = client.getUrl(new Uri(url)); conn.onResponse = (HttpClientResponse resp) { print ('content length ${resp.contentLength}'); print ('status code ${resp.statusCode}'); InputStream input = resp.inputStream; input.onData = () { print(codepointsToString(input.read())); }; input.onClosed = () { print('closed!'); client.shutdown(); }; }; 

Please note that if I replace the URL with β€œhttp” instead of β€œhttps”, it works as expected.

Error report here.

+3
source share
2 answers

Update : see William Hesse's answer for Dart> = 1.12.


I have the same error with Dart SDK version 0.2.9.9_r16323 . To question 7541 :

Before using a secure network, you must explicitly initialize the SecureSocket library. We are working to ensure that it is automatically initialized upon first use, but this has not yet been done. To use only the default root certificates (known certification authorities), call SecureSocket.initialize() in your main () procedure before performing any network operations.

Thus, by adding SecureSocket.initialize() in front of your code, it works as expected.

After r16384, this explicit initialization is optional .

SecureSocket.initialize() now optional. If you do not name it, it will be the same as if you named it without parameters. If you invoke this explicitly, you must do this once before creating any secure connections. You need to call it explicitly if you are creating server sockets , as they need a certificate database and a password for the key database.

+3
source

Since this question was written, the secure network library has changed. The SecureSocket.initialize () function is no longer present, and many other methods and objects have changed names. Working equivalent code for Dart 1.12 and later:

 import "dart:io"; main() async { Uri url = Uri.parse("https://www.google.com");` var client = new HttpClient(); var request = await client.getUrl(url); var response = await request.close(); var responseBytes = (await response.toList()).expand((x) => x); print(new String.fromCharCodes(responseBytes)); client.close(); } 
+1
source

Source: https://habr.com/ru/post/1480506/


All Articles