我正在尝试向 SMTP 服务器发送 EHLO 命令。连接成功,但我似乎无法从中读取任何数据:
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();
}
print 语句的输出总是 \u000(null)