SocketException:软件导致连接中止

时间:2019-04-28 11:24:45

标签: 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);

连接套接字后,循环执行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.iott.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手机测试没有问题。

0 个答案:

没有答案