int receive ( byte [ ] b , int offset , int length ) throws IOException , InterruptedException { synchronized ( readLock ) { if ( remaining > 0 ) { int bytesToRead = Math . min ( remaining , length ) ; int result = stdin . read ( b , offset , bytesToRead ) ; remaining -= result ; return result ; } if ( eof ) { return - 1 ; } } // make client know we want more data! sendSendInput ( ) ; synchronized ( readLock ) { if ( remaining == 0 && ! eof ) { readLock . wait ( ) ; } // at this point we should have data so call itself recursively to utilize // reentrant lock return receive ( b , offset , length ) ; } }
Read data from client s stdin . This function blocks till input is received from the client .