# Reading rompt protocols

**URL:** <https://www.ruby-forum.com/t/reading-rompt-protocols/54120>\
**Category:** Ruby\
**Created:** [February 23, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/reading-rompt-protocols/54120 "2006-02-23T17:12:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mihai\_Vlad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e495f1/32.png) [@Mihai\_Vlad](https://www.ruby-forum.com/u/Mihai_Vlad)\
**Post date:** [February 23, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/reading-rompt-protocols/54120/1 "2006-02-23T17:12:00Z")

</div>

I’m trying to implement a function that reads from a socket ( TCP/IP  
based protocol with prompt ).

Server sends:

Welcoming you\r\n  
Please login\r\n

I need this function to be a wrapper for gets (readline), that would  
read each line of the 3. The problem is that only the first two lines  
end in CRLF( or only \n doesn’t really matter ). I’ve tried rewriting  
something like:

```
def _gets()
    c = ''
    answer = ''

    while true
        c = @sock.sysread( 1 )
        if c == "" then
            break
        end

        #adding the character to the string
        answer = answer+c

        if c.match("\n") then
            break
        end
    end

    return answer
end

```

The bad part is that sysread hangs on trying to read the socket.

I’ve used this pseudo code in pearl, but there the sysread function  
would return \>0 or 0 in case of error. [ if ( sysread( $sock, $char, 1)

> 0 ) {…} ]

I’m not interested in time outing the sysread function nor using a  
single recv function, so please, can someone please tell me a solution?
