xuuhaoo/OkSocket

read head is wrong, this socket input stream is end of file read " + value +" ,that mean this socket is disconnected by server

298068845 opened this issue · 10 comments

点击按钮发送消息到服务器,获得服务器的返回,打点看readHeaderFromChannel() i从0开始,一直循环4次,header的value没有-1,正常读取结束。
第二次接受服务器的返回的时候,readHeaderFromChannel() for循环4次以后,代码已经执行到 mStateSender.sendBroadcast(IOAction.ACTION_READ_COMPLETE, originalData);不知道为什么AbsLoopThread里的isStop没有变true,因此又开始了一次循环,readHeaderFromChannel的i重新变为了0,然后读取到value是-1,就抛出read head is wrong这个报错了。可以确认不是服务器返回的问题

private void initManager() {
final Handler handler = new Handler();
mInfo = new ConnectionInfo(mIPET.getText().toString(), Integer.parseInt(mPortET.getText().toString()));
mOkOptions = new OkSocketOptions.Builder()
.setReconnectionManager(new NoneReconnect())
.setConnectTimeoutSecond(10)
.setCallbackThreadModeToken(new OkSocketOptions.ThreadModeToken() {
@OverRide
public void handleCallbackEvent(ActionDispatcher.ActionRunnable runnable) {
handler.post(runnable);
}
})
.build();
mManager = OkSocket.open(mInfo).option(mOkOptions);
mManager.registerReceiver(adapter);
mManager.connect();
}
option基本是照搬SimpleDemoActivity里的,只是直接在init里connect

我们看下这个问题

我也是,一链接服务端,没发消息,就老是自动断开报这个问题

我也碰到了这个问题

2020-12-06 12:26:06.846 12004-12263/com.xx I/System.out: OkSocket, bytes write length:10240
2020-12-06 12:26:06.846 12004-12273/com.xx I/System.out: OkSocket, mActionHandler is detached.
2020-12-06 12:26:06.846 12004-12263/com.xx W/System.err: OkSocket, duplex write error,thread is dead with exception:com.xuhao.didi.core.exceptions.ReadException: read head is wrong, this socket input stream is end of file read -1 ,that mean this socket is disconnected by server
2020-12-06 12:26:06.846 12004-12273/com.xx W/System.err: OkSocket, socket is disconnecting because: com.xuhao.didi.core.exceptions.ReadException: read head is wrong, this socket input stream is end of file read -1 ,that mean this socket is disconnected by server
2020-12-06 12:26:06.846 12004-12263/com.xx I/System.out: OkSocket, client_duplex_write_thread is shutting down

这个问题怎么解决呢

I have also the same issue. don't know how to pass the header from the client side. please share some sample how to send message from client side with header which can be read from our code as server.

我也碰到了这个问题

2020-12-06 12:26:06.846 12004-12263/com.xx I/System.out: OkSocket, bytes write length:10240 2020-12-06 12:26:06.846 12004-12273/com.xx I/System.out: OkSocket, mActionHandler is detached. 2020-12-06 12:26:06.846 12004-12263/com.xx W/System.err: OkSocket, duplex write error,thread is dead with exception:com.xuhao.didi.core.exceptions.ReadException: read head is wrong, this socket input stream is end of file read -1 ,that mean this socket is disconnected by server 2020-12-06 12:26:06.846 12004-12273/com.xx W/System.err: OkSocket, socket is disconnecting because: com.xuhao.didi.core.exceptions.ReadException: read head is wrong, this socket input stream is end of file read -1 ,that mean this socket is disconnected by server 2020-12-06 12:26:06.846 12004-12263/com.xx I/System.out: OkSocket, client_duplex_write_thread is shutting down

请问解决了没,用什么办法呢?

我通过模拟了个客户端,连接我的服务器端。后来发现:如果客户端在收到服务器的心跳包不喂狗的话,发送次数达到一定之后就会出现这个问题。
所以客户端收到服务器的心跑包之后记得要喂狗,不然就会被强制断开连接。

我通过模拟了个客户端,连接我的服务器端。后来发现:如果客户端在收到服务器的心跳包不喂狗的话,发送次数达到一定之后就会出现这个问题。 所以客户端收到服务器的心跑包之后记得要喂狗,不然就会被强制断开连接。

怎么喂狗,方法是啥

我通过模拟了个客户端,连接我的服务器端。后来发现:如果客户端在收到服务器的心跳包不喂狗的话,发送次数达到一定之后就会出现这个问题。 所以客户端收到服务器的心跑包之后记得要喂狗,不然就会被强制断开连接。

怎么喂狗,方法是啥

IConnectionManager manager = OkSocket.open(connectionInfo);
manager.getPulseManager().feed();