dart - Flutter - SocketException:连接失败(操作系统错误:网络无法访问,errno = 101)
问题描述
连接到以太坊节点时出错
E/flutter(23790):[错误:flutter/lib/ui/ui_dart_state.cc(148)]未处理的异常:SocketException:连接失败(操作系统错误:网络无法访问,errno = 101)
---------------------------------- web3连接代码如下------------ ----------------------------------
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());
}
解决方案
我仍然无法弄清楚为什么这个解决方案有效,但我遇到了同样的问题,我试图localhost
用我的服务器的 IP 地址替换(例如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());
}
推荐阅读
- reactjs - array[index].object 在 ReactJS 中不起作用
- mysql - 与 SQL 数据库中的触发器触发相关的查询?
- java - 通过不更改其原始位置对大写和小写字母进行排序
- meshlab - 如何将 xyz 点转换为 xyz 球体
- javascript - Handling new websocket connections in express-ws
- oracle11g - Use edition based redefinition from oracle with liquibase
- python - Scrapy 错误(不支持的 url 方案 javascript)
- build - 如果它们已经存在,如何停止 cmake 重建静态库
- c++ - 如何在 C++ 中的 .txt 文件中查找值?
- sql - 我如何过滤掉SQL中的重复行