NIO Sockets make this a non-trivial task but there is already an example in netty-3.10.4.Final/src/main/java/org/jboss/netty/example/securechat.