*/
public class HelloWorld {
public static void main(String[] args) {
// create new session
Session session = new PipeSession();
// set packet encoder and decoder
session.setPacketEncoder(new SerialEncoder());
session.setPacketDecoder(new SerialDecoder());
// set session handler
session.setSessionHandler(new SessionHandlerAdapter() {
public void sessionStarted(Session session) throws Exception {
System.out.println("session started");
}
public void sessionClosed(Session session) throws Exception {
System.out.println("session closed");
}
public void objectReceived(Session session, Object obj)
throws Exception {
System.out.println("received " + obj.getClass().getName()
+ " : " + obj);
}
});
// start session
session.start().complete();
// start send
session.send("hello, world!");
session.send(new Integer(Integer.MAX_VALUE));
session.send(new Double(Math.random()));
session.send(new User("User 1", 20));
// send object and close the session
session.send("bye!").addListener(new FutureListener() {
public void futureCompleted(Future future) throws Exception {
future.getSession().close();
}
});