Code example for Socket

Methods: getInputStream, getOutputStream

0
        long lastTime = System.currentTimeMillis();
 
        private static final int HEADER_SIZE = 24;
 
        public LogReader() throws IOException { 
            this.socket = new Socket("127.0.0.1", 5040);
            this.in = new DataInputStream(this.socket.getInputStream());
            // Write two newlines to indicate "no reader args" 
            this.socket.getOutputStream().write('\n');
            this.socket.getOutputStream().write('\n');
        } 
 
        public void run() { 
            while (active) {
                try { 
                    while (in.available() > 0) {
                        logger.write("Reading message.\n".getBytes());
 
                        int length = in.readInt();
                        byte[] bytes = new byte[length];
                        in.readFully(bytes);