android - SocketException:软件导致连接中止
问题描述
我遇到了这个异常:java.net.SocketException:软件导致连接中止,谁能帮帮我。
socket.connect(new InetSocketAddress(Constant.IP_FLY, Constant.PORT_FLY),5000);
in = socket.getInputStream();
out = socket.getOutputStream();
dataOutputStream = new DataOutputStream(out);
dataInputStream = new DataInputStream(in);
protected byte[] readData = new byte[2048];
dataInputStream.read(readData);
socket连接后,循环执行dataInputStream.read(readData),遇到异常:
System.err: java.net.SocketException: Software caused connection abort
System.err: at java.net.SocketInputStream.socketRead0(Native Method)
System.err: at java.net.SocketInputStream.socketRead(SocketInputStream.java:114)
System.err: at java.net.SocketInputStream.read(SocketInputStream.java:170)
System.err: at java.net.SocketInputStream.read(SocketInputStream.java:139)
System.err: at java.io.DataInputStream.read(DataInputStream.java:103)
System.err: at iot.android.com.iott.connection.TcpConnection.readDataBlock(TcpConnection.java:134)
System.err: at iot.android.com.iott.connection.MAVLinkConnection.run(MAVLinkConnection.java:87)
例外是 dataInputStream.read(readData),即 iot.android.com.iot.connection.TcpConnection.readDataBlock(TcpConnection.java:134)。有没有人遇到过,不胜感激!
readDataBlock在run方法中执行,readDataBlock主要用于读取数据:
while(connect){ dataInputStream.read(readData);}. //connect true:connect,false:disconnect
好像和手机有关。我的手机Android 8.1.0会报上述异常,但是使用8.0手机测试没有问题。
解决方案
推荐阅读
- html - 如何在最新的 Swift 版本 Swift 5 Xcode 10.2 的 Web 视图中显示 html 文件
- ros - 机器人无法在 Webots 环境中移动
- reactjs - 在此服务器上找不到隐式回调 - 反应和节点快递 - 在 Azure 上部署
- c++ - Gradle Cpp-Application 未在 Windows 中检测到 gcc
- c++ - 如何检查表达式是否是函数名?
- php - 如何使用 fetch 函数从数据库中获取的数据只获取一个值
- cakephp - HasOne 关联表未保存
- wordpress - 如何在wordpress rest api中过滤自定义帖子类型的自定义字段?
- bash - 完成第一个循环后,循环退出的 Shell 脚本
- javascript - 下划线 js - Uncaught SyntaxError: Unexpected token if