I'm trying to send an EHLO command to an SMTP server. The connection succeeds, but I can't seem to read any data from it:
ByteBuffer byteBuffer = null;
try {
socketChannel = SocketChannel.open();
socketChannel.connect(new InetSocketAddress("host", 25));
socketChannel.configureBlocking(true);
byteBuffer = ByteBuffer.allocateDirect(4 * 1024);
} catch (Exception e) {
e.printStackTrace();
}
try {
byteBuffer.clear();
socketChannel.write(byteBuffer.put(SMTP_EHLO.getBytes()));
byteBuffer.flip();
socketChannel.read(byteBuffer);
byteBuffer.get(subStringBytes);
String ss = new String(subStringBytes);
System.out.println(byteBuffer);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
The output of the print statement is always u000(null)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…