public String getresp_first ( int maxbytes , int timeout ) throws SoccomException { int n ; String sizestr , msg ; _resp_read = - 1 ; try { byte [ ] _header = new byte [ SoccomMessage . HEADER_SIZE ] ; _socket . setSoTimeout ( timeout * 1000 ) ; n = _in . read ( _header , 0 , SoccomMessage . HEADER_SIZE ) ; if ( n != SoccomMessage . HEADER_SIZE ) throw new SoccomException ( SoccomException . RECV_HEADER ) ; logline ( "RECV HDR: " + new String ( _header ) ) ; check_msgid ( _msgid , _header ) ; sizestr = new String ( _header , SoccomMessage . MSGSIZE_OFFSET , 8 ) ; if ( sizestr . startsWith ( "ENDM" ) ) _resp_size = - 1 ; else _resp_size = Integer . parseInt ( sizestr ) ; } catch ( InterruptedIOException e ) { throw new SoccomException ( SoccomException . RECV_HEADER ) ; } catch ( IOException e ) { throw new SoccomException ( SoccomException . RECV_HEADER ) ; } try { if ( maxbytes == 0 ) { if ( _resp_size == - 1 ) { _endm = sizestr . substring ( 4 , 8 ) ; } _resp_read = 0 ; if ( getresp_hasmore ( ) ) msg = getresp_next ( maxbytes ) ; else msg = "" ; } else if ( _resp_size == - 1 ) { _endm = sizestr . substring ( 4 , 8 ) ; byte [ ] buffer = new byte [ maxbytes ] ; int k = 0 ; boolean done = false ; while ( ! done && k < maxbytes ) { n = readLine ( _in , buffer , k , maxbytes ) ; if ( n == 5 && _endm . equals ( new String ( buffer , k , 4 ) ) ) { done = true ; } else k += n ; } if ( done ) _resp_read = - 1 ; else _resp_read = k ; msg = new String ( buffer , 0 , k ) ; logline ( "RECV MSG: " + msg ) ; } else { byte [ ] buffer = new byte [ maxbytes ] ; if ( _resp_size <= maxbytes ) { n = _in . read ( buffer , 0 , _resp_size ) ; } else { n = _in . read ( buffer , 0 , maxbytes ) ; } if ( n >= 0 ) { _resp_read = n ; msg = new String ( buffer , 0 , n ) ; } else if ( n == - 1 ) throw new SoccomException ( SoccomException . SOCKET_CLOSED ) ; else throw new SoccomException ( SoccomException . RECV_ERROR ) ; logline ( "RECV MSG: " + msg ) ; } return msg ; } catch ( InterruptedIOException e ) { throw new SoccomException ( SoccomException . RECV_ERROR ) ; } catch ( IOException e ) { throw new SoccomException ( SoccomException . RECV_ERROR ) ; } }
The method receives the first part of response message from the server up to maxbytes bytes . Use getresp_hasmore and getresp_next to get getresp_rest to get the remaining part of messages . When the server sends the message using ENDM the string returned may be longer than maxbytes but only till the first line after that . When maxbytes is 0 the procedure reads the first line .