Package kilim.nio

Examples of kilim.nio.EndPoint


    public static class EchoServer extends SessionTask {
        @Override
        public void execute() throws Pausable, Exception {
            ByteBuffer buf = ByteBuffer.allocate(100);
            EndPoint ep = getEndPoint();
            while (true) {
                buf.clear();
                buf = ep.fillMessage(buf, 4, /*lengthIncludesItself*/ false);
                buf.flip();
                int strlen = buf.getInt();
                String s= new String(buf.array(), 4, strlen);
                //System.out.println ("Rcvd: " + s);
                if (!s.startsWith("Iteration #")) {
                    ep.close();
                    break;
                }
                buf.position(0); // reset read pos
                ep.write(buf); // echo.
                if (s.endsWith("DONE")) {
                    ep.close();
                    break;
                }
            }
        }
View Full Code Here


        @Override
        public void execute() throws Pausable, Exception {
            System.out.println("[" + this.id + "] Connection rcvd");
            try {
                while (true) {
                    EndPoint ep = getEndPoint();
                    ByteBuffer buf = ByteBuffer.allocate(PACKET_LEN);
                    buf = ep.fill(buf, PACKET_LEN); // Pauses until at least PACKET_LEN bytes have been rcvd in buf.
                    System.out.println("[" + this.id + "] Received pkt");
                    buf.flip();
                    ep.write(buf);
                    System.out.println("[" + this.id + "] Echoed pkt");
                }
            } catch (EOFException eofe) {
                System.out.println("[" + this.id + "] Connection terminated");
            } catch (IOException ioe) {
View Full Code Here

TOP

Related Classes of kilim.nio.EndPoint

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.