Package net.sf.cindy.session.nio

Examples of net.sf.cindy.session.nio.PipeSession


*/
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();
            }
        });
View Full Code Here

TOP

Related Classes of net.sf.cindy.session.nio.PipeSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.