查了几天资料都是说使用mSocket.sendUrgentData(0xFF);来判断是否断开,使用之后就是无效。
看了github的OkSocket源码
使用到一下代码可以监听是否断开,亲测有效。
byte[] bytes =new byte[1];
int value =mSocket.getInputStream().read(bytes);
if (value == -1) {
throw new Exception(
"read head is wrong, this socket input stream is end of file read " + value +" ,that mean this socket is disconnected by server");
}
网友评论