首页 > 解决方案 > 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手机测试没有问题。

标签: androidsocketexception

解决方案


推荐阅读