Package net.sf.cindy

Examples of net.sf.cindy.Session


        }
        boolean tcp = "tcp".equalsIgnoreCase(args[0]);
        String host = args[1];
        int port = Integer.parseInt(args[2]);

        Session session = startSession(tcp, host, port);

        byte[] b = new byte[4096];
        while (true) {
            int count = System.in.read(b);
            if (count < 0)
                break;
            // block send
            if (!session.send(BufferFactory.wrap(b, 0, count)).complete())
                break;
        }
    }
View Full Code Here


        }
    }

    private static Session startSession(boolean tcp, String host, int port) {
        System.out.println("start telnet using " + (tcp ? "tcp" : "udp"));
        Session session = SessionFactory.createSession(tcp ? SessionType.TCP
                : SessionType.UDP);
        session.setRemoteAddress(new InetSocketAddress(host, port));

        // set packet encoder and decoder
        session.setPacketEncoder(new BufferEncoder());
        session.setPacketDecoder(new PacketDecoder() {

            public Object decode(Session session, Packet packet)
                    throws Exception {
                Buffer content = packet.getContent();
                return content.getString(Charset.SYSTEM, content.remaining());
            }
        });

        // set session handler
        session.setSessionHandler(new SessionHandlerAdapter() {

            public void objectReceived(Session session, Object obj)
                    throws Exception {
                System.out.println(obj);
            };
        });

        // start session
        session.start().complete();
        return session;
    }
View Full Code Here

    private void send(Session srcSession, String message) {
        // send message to other user
        synchronized (sessions) {
            for (Iterator iter = sessions.iterator(); iter.hasNext();) {
                Session session = (Session) iter.next();
                if (session != srcSession) {
                    session.send(message);
                }
            }
        }
    }
View Full Code Here

        }
        SocketAddress address = new InetSocketAddress(args[1], Integer
                .parseInt(args[2]));
        System.out.println("start transfer " + file + " to " + address);

        Session session = SessionFactory.createSession(SessionType.TCP);
        session.setRemoteAddress(address);
        session.setPacketEncoder(new BufferEncoder());
        session.setSessionHandler(new FileTransferHandler(file));
        session.start();
    }
View Full Code Here

*/
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

public class ChatLogFilter extends SessionFilterAdapter {

    private static final Object ADDR_ATTR = "remoteAddr";

    public void sessionStarted(SessionFilterChain filterChain) throws Exception {
        Session session = filterChain.getSession();
        SocketAddress address = session.getRemoteAddress();
        session.setAttribute(ADDR_ATTR, address);
        System.out.println(address + " log in");
        super.sessionStarted(filterChain);
    }
View Full Code Here

            handler.objectReceived(session, obj);
    }

    public void objectSent(SessionFilterChain filterChain, Object obj)
            throws Exception {
        Session session = filterChain.getSession();
        SessionHandler handler = session.getSessionHandler();
        if (handler != null)
            handler.objectSent(session, obj);
    }
View Full Code Here

        if (handler != null)
            handler.objectSent(session, obj);
    }

    public void sessionClosed(SessionFilterChain filterChain) throws Exception {
        Session session = filterChain.getSession();
        SessionHandler handler = session.getSessionHandler();
        if (handler != null)
            handler.sessionClosed(session);
    }
View Full Code Here

        if (handler != null)
            handler.sessionClosed(session);
    }

    public void sessionStarted(SessionFilterChain filterChain) throws Exception {
        Session session = filterChain.getSession();
        SessionHandler handler = session.getSessionHandler();
        if (handler != null)
            handler.sessionStarted(session);
    }
View Full Code Here

        if (handler != null)
            handler.sessionStarted(session);
    }

    public void sessionTimeout(SessionFilterChain filterChain) throws Exception {
        Session session = filterChain.getSession();
        SessionHandler handler = session.getSessionHandler();
        if (handler != null)
            handler.sessionTimeout(session);
    }
View Full Code Here

TOP

Related Classes of net.sf.cindy.Session

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.