Code example for SocketChannel

Methods: readclose

0
     */ 
    public int read(SelectionKey key) throws IOException{
        SocketChannel channel = (SocketChannel) key.channel();
         
        readBuffer.clear();
        int count = channel.read(readBuffer);
         
        if(count == -1){
            try 
            { 
                channel.close();
                System.out.println("read error:count = -1,  close");
            } catch (IOException e1)
            { 
                e1.printStackTrace();
            } 
            return -1; 
        } 
        readBuffer.rewind();
        byte b = readBuffer.get(); 
Experience pair programming with AI  Get Codota for Java