我的代码是通过Android 7中的套接字发送和接收数据的问题。
socket = new Socket(IPaddr, port);
OutputStream out = socket.getOutputStream();
out.write(buffer);
InputStream inputStream = socket.getInputStream();
int i1 = inputStream.read(frame);
line = "";
if (i1 > 0)
for (int i = 0; i < i1; i++)
line += (char) frame[i];
response = line;
out.close();
inputStream.close();
问题在于此代码在Android Lollipop上完美运行,而在Android Nougat上运行不正常。我得到的错误是:
java.net.SocketException: Software caused connection abort
并指向socket = new Socket(IPaddr, port);
此代码用于连接和发送数据到启用wifi的设备(设备处于AP模式)