I'm trying to send data (400016 bytes) via SocketChannel. for some reason not all the data is being sent. (I expect to see that all the 400016 bytes will be sent)
Here's the code: public boolean send(byte[] bytesPayload, int nSize) {
System.out.print("\nNeed to send message of size: " + nSize);
m_sendBuf.clear();
m_sendBuf.put(bytesPayload);
m_sendBuf.flip();
try {
int nNumOfSentBytes = 0;
int nTotalNumOfSentBytes = 0;
while(nTotalNumOfSentBytes < nSize) {
System.out.print("\nBefore write oper: pos:" + m_sendBuf.position() + " limit: " + m_sendBuf.limit() + " remainging: " + m_sendBuf.remaining() + " has remaining: " + m_sendBuf.hasRemaining());
nNumOfSentBytes += m_socketChannel.write(m_sendBuf);
System.out.print("\nAfter write oper: pos:" + m_sendBuf.position() + " limit: " + m_sendBuf.limit() + " remainging: " + m_sendBuf.remaining() + " has remaining: " + m_sendBuf.hasRemaining());
nTotalNumOfSentBytes += nNumOfSentBytes;
System.out.print("\nsent " + nNumOfSentBytes + " bytes");
}
} catch (IOException e) {
System.out.print("\n" + e);
return false;
}
System.out.print("\nFinish sending data");
return true;
}
I'm calling the function with byte[] of 400016.
I'm getting the following prints: Need to send message of size: 400016 Before write oper: pos:0 limit: 400016 remainging: 400016 has remaining: true After write oper: pos:262142 limit: 400016 remainging: 137874 has remaining: true sent 262142 bytes Before write oper: pos:262142 limit: 400016 remainging: 137874 has remaining: true After write oper: pos:262142 limit: 400016 remainging: 137874 has remaining: true sent 262142 bytes Finish sending data