def frame_read(socket)
      begin
        socket_content = socket.read_nonblock(4096)
        frame = Hash.new
        if match = socket_content.match(/(^[0-9]+) ([\S]*) (\d+)([\s\S]*)/)
          frame[:txnr], frame[:command], frame[:data_length], frame[:message] = match.captures
          # check_message_length(frame) - currently unstable, needs some more work
          frame[:message].lstrip! #message could be empty
        else
          raise Relp::FrameReadException.new('Problem with reading RELP frame')
        end
        @logger.debug "Reading Frame #{frame.inspect}"
      rescue IOError
        @logger.error 'Problem with reading RELP frame'
        raise Relp::FrameReadException.new 'Problem with reading RELP frame'
      rescue Errno::ECONNRESET
        @logger.error 'Connection reset'
        raise Relp::ConnectionClosed.new 'Connection closed'
      end
      is_valid_command(frame[:command])

      return frame
    end
def frame_read(socket)
      begin
        socket_content = socket.read_nonblock(4096)
        frame = Hash.new
        if match = socket_content.match(/(^[0-9]+) ([\S]*) (\d+)([\s\S]*)/)
          frame[:txnr], frame[:command], frame[:data_length], frame[:message] = match.captures
          # check_message_length(frame) - currently unstable, needs some more work
          frame[:message].lstrip! #message could be empty
        else
          raise Relp::FrameReadException.new('Problem with reading RELP frame')
        end
        @logger.debug "Reading Frame #{frame.inspect}"
      rescue IOError
        @logger.error 'Problem with reading RELP frame'
        raise Relp::FrameReadException.new 'Problem with reading RELP frame'
      rescue Errno::ECONNRESET
        @logger.error 'Connection reset'
        raise Relp::ConnectionClosed.new 'Connection closed'
      end
      is_valid_command(frame[:command])

      return frame
    end
Read socket and return Relp frame information in hash