The issue here is I can see that the data is being written out to the socket but it is not ALWAYS being sent.
Here’s a code sniplet
ByteBuffer writeBuffer = ByteBuffer.allocate(8192);
writeBuffer.clear();
writeBuffer.put("heartbeat".getBytes());
writeBuffer.flip();
LOG.debug("is connected: " + socketChannel.isConnected());
int bytesWritten = 0;
if (key.isWritable()) {
while (writeBuffer.hasRemaining()) {
bytesWritten += socketChannel.write(writeBuffer);
}
}
I use TCPMon to see if the actual data gets written out to the socket – WHICH it does.
But using WireShark (another network monitoring tool) I cannot see the packet going through the NIC.
Any help would be appreciated
Your code is wrong anyway. If the write returns zero the socket send buffer is full, so you should register OP_WRITE and return to the select loop, rather than waste time spinning until there is room again. Your present technique starves the other channels of service and wastes CPU cycles.
Also, testing
isConnected()at this point is futile. It is. You connected it. That method tells you about the state of the socket, not the connection.