Package net.sf.cindy.packet

Examples of net.sf.cindy.packet.DefaultPacket


*/
public class DaytimeHandler extends SessionHandlerAdapter {

    public void sessionStarted(Session session) throws Exception {
        ByteBuffer buffer = Charset.UTF8.encode(new Date().toString());
        Future future = session.flush(new DefaultPacket(buffer));
        future.addListener(new FutureListener() {

            public void futureCompleted(Future future) throws Exception {
                future.getSession().close();
            }
View Full Code Here


        response.setParam("Server", "Cindy Http Server");
        response.setParam("Connection", keepAlive ? "keep-alive" : "close");

        Future future = session.send(response); // send http header
        if (content != null)
            future = session.flush(new DefaultPacket(content)); // send content
        if (!keepAlive)
            future.addListener(new FutureListener() {

                public void futureCompleted(Future future) throws Exception {
                    future.getSession().close();
View Full Code Here

    private static class ChatMessageEncoder implements PacketEncoder {

        public Packet encode(Session session, Object obj) throws Exception {
            String s = (String) obj;
            ByteBuffer buffer = Charset.SYSTEM.encode(s);
            return new DefaultPacket(BufferFactory.allocate(
                    buffer.remaining() + TOKEN.length).put(buffer).put(TOKEN)
                    .flip());
        }
View Full Code Here

    public void sessionStarted(Session session) throws Exception {
        send(session);
    }

    private void send(Session session) {
        session.flush(new DefaultPacket(DATA)).addListener(
                new FutureListener() {

                    public void futureCompleted(Future future) throws Exception {
                        if (future.isSucceeded())
                            send(future.getSession());
View Full Code Here

            buffer.put(header).put(response.getContent()).flip();
        } else {
            buffer = BufferFactory.wrap(header);
        }

        return new DefaultPacket(buffer);
    }
View Full Code Here

        }

        src.release();
        if (hasAppData) {
            dest.position(0).limit(destBuffer.position());
            return new DefaultPacket(dest, packet.getAddress());
        }
        return null;
    }
View Full Code Here

            }
        }

        src.release();
        dest.position(0).limit(destBuffer.position());
        return new DefaultPacket(dest, packet.getAddress());
    }
View Full Code Here

*/
public class BufferEncoder implements PacketEncoder {

    public Packet encode(Session session, Object obj) throws Exception {
        if (obj instanceof Buffer)
            return new DefaultPacket((Buffer) obj);
        return null;
    }
View Full Code Here

*/
public class ByteArrayEncoder implements PacketEncoder {

    public Packet encode(Session session, Object obj) throws Exception {
        if (obj instanceof byte[])
            return new DefaultPacket((byte[]) obj);
        return null;
    }
View Full Code Here

                                builder.append(ByteBuffer.wrap(b, off, len));
                            }
                        });
                oos.writeUnshared(obj);
                oos.close();
                return new DefaultPacket(builder.toBuffer());
            } finally {
                builder.release();
            }
        }
        return null;
View Full Code Here

TOP

Related Classes of net.sf.cindy.packet.DefaultPacket

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.