SocketIOException:客户端中出现意外的握手错误 [英] SocketIOException: Unexpected handshake error in client

查看:964
本文介绍了SocketIOException:客户端中出现意外的握手错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下例外:

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)

源于以下代码:

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();
  };
};

请注意,如果我将网址替换为http而不是https

Bug report is here.

推荐答案

更新:请参阅Dart版本> = 1.12的回答William Hesse

Update: See the answer of William Hesse for Dart version >= 1.12.

我有与 Dart SDK版本0.2.9.9_r16323 相同的错误。在问题7541 中:

I have the same error with Dart SDK version 0.2.9.9_r16323. In the issue 7541 :


SecureSocket库需要在使用安全网络之前明确初始化。我们正在努力使它在第一次使用时自动初始化,但这还没有提交。要使用默认的根证书(众所周知的证书颁发机构),在你做任何网络之前,在main()例程中调用 SecureSocket.initialize()

因此,在代码之前加入 SecureSocket.initialize()

Thus, by adding SecureSocket.initialize() before your code, it works as expected.

r16384 此显式初始化是可选的

After r16384 this explicit initialization is optional.


SecureSocket.initialize()现在是可选的。如果你不调用它,它就像没有调用它的参数一样。如果您明确调用它,您必须这样做,并在创建任何安全连接之前。 如果您正在制作服务器套接字,则需要明确调用它,因为它们需要证书数据库和密钥数据库的密码。

SecureSocket.initialize() is now optional. If you don't call it, it is the same as if you had called it with no parameters. If you call it explicitly, you must do so once, and before creating any secure connections. You need to call it explicitly if you are making server sockets, since they need a certificate database and a password for the key database.

这篇关于SocketIOException:客户端中出现意外的握手错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆