public String getresp ( int timeout ) throws SoccomException { int size , n ; String sizestr ; 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" ) ) size = - 1 ; else size = Integer . parseInt ( sizestr ) ; } catch ( InterruptedIOException e ) { throw new SoccomException ( SoccomException . POLL_TIMEOUT ) ; } catch ( IOException e ) { throw new SoccomException ( SoccomException . RECV_HEADER ) ; } try { String msg ; if ( size == - 1 ) { String endm = sizestr . substring ( 4 , 8 ) ; String line ; StringBuffer sb = new StringBuffer ( ) ; byte [ ] buffer = new byte [ 1024 ] ; int k ; boolean done = false ; while ( ! done ) { k = readLine ( _in , buffer , 0 , 1024 ) ; line = new String ( buffer , 0 , k ) ; if ( k == 5 && line . startsWith ( endm ) ) done = true ; else sb . append ( line ) ; } msg = sb . toString ( ) ; } else { byte [ ] buffer = new byte [ size + SoccomMessage . HEADER_SIZE ] ; int got = 0 ; while ( got < size ) { n = _in . read ( buffer , got , size - got ) ; if ( n > 0 ) got += n ; else if ( n == - 1 ) throw new SoccomException ( SoccomException . SOCKET_CLOSED ) ; else throw new SoccomException ( SoccomException . RECV_ERROR ) ; } msg = new String ( buffer , 0 , size ) ; } logline ( "RECV MSG: " + msg ) ; return msg ; } catch ( InterruptedIOException e ) { throw new SoccomException ( SoccomException . RECV_ERROR ) ; } catch ( IOException e ) { throw new SoccomException ( SoccomException . RECV_ERROR ) ; } }
Get the response from the server after sending a request .