Flutter-插座异常:连接失败(操作系统错误:网络无法访问,错误号= 101)

gojuced7  于 2023-01-27  发布在  Flutter
关注(0)|答案(1)|浏览(179)

连接到以太坊节点时出错
E/扑动(23790):[错误:flutter/lib/ui/ui_dart_state.cc(148)]未处理的异常:套接字异常:连接失败(操作系统错误:网络无法访问,错误号= 101)
------------------------------web 3连接代码如下-----------------------------------------------------------

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
import 'dart:async';

const String rpcUrls = 'https://node1.bitcoiin.com';
class HomeScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeScreenState();
  }
}
class _HomeScreenState extends State<HomeScreen> {
  @override
  void initState() {
    main();
    super.initState();
  }
  main(){
  var ethClient = new Web3Client(apiUrls, new Client());
  print(ethClient.getBlockNumber());
}
htzpubme

htzpubme1#

我仍然不知道为什么这个解决方案的作品,但我有同样的问题,我试图取代localhost的IP地址到我的服务器(e.g. 192.168.1.33).
请为您的应用尝试以下代码:

main(){
  var httpClient = new Client();
  // You tried the code below and it didn't work
  // var ethClient = new Web3Client('http://localhost:8545', httpClient);

  // Try this code instead. (Replace "192.168.1.33" with the IP of your server)
  var ethClient = new Web3Client('http://192.168.1.33:8545', httpClient);

  print(ethClient.getBlockNumber());
}

相关问题