NIO Netty客户端服务器中的数据加密和解密
我是NIO和Netty服务器客户机框架的新手,我想在NIOClientNew.java中加密我的数据(“Hello!”,如类NIOClientNew.java所示),并将其发送到Netty服务器,并在Netty handler类中解密数据 有没有人建议我在NIO和Netty中如何进行数据加密和解密NIO Netty客户端服务器中的数据加密和解密,netty,nio,Netty,Nio,我是NIO和Netty服务器客户机框架的新手,我想在NIOClientNew.java中加密我的数据(“Hello!”,如类NIOClientNew.java所示),并将其发送到Netty服务器,并在Netty handler类中解密数据 有没有人建议我在NIO和Netty中如何进行数据加密和解密 'import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; impor
'import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
public class NIOClientNew {
public static final String HELLO_REQUEST = "Hello!";
public static void main(String arg[]) {
SocketChannel sc = null;
try {
sc = SocketChannel.open();
sc.configureBlocking(false);
sc.connect(new InetSocketAddress(6565));
System.out.println("Sending a request to HelloServer");
while (!sc.finishConnect()) {
}
ByteBuffer buffer = ByteBuffer.allocate(65535);
buffer.putInt(HELLO_REQUEST.length());
buffer.put(HELLO_REQUEST.getBytes());
buffer.flip();
try {
sc.write(buffer);
} catch (IOException ex) {
System.out.println(ex.toString());
}
} catch (Exception e) {
System.out.println(e.toString());
} finally {
if (sc != null) {
try {
sc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
'
您可以将
SslHandler
放入管道中吗?请看一下SecureChat示例。将套接字置于非块模式,然后调用connect(),然后在finishConnect()中旋转循环是毫无意义的。如果在连接时没有其他事情要做,请以阻塞模式连接,并节省CPU。