TCPConnectionGetLine

function

Library: TCP/IP client and server support (OMTCP legacy, OmniMark versions 4 - 6.0.1)
Include: omtcp.xin

Returns: Characters up to and including the next line-end sequence.


Declaration
define external stream function TCPConnectionGetLine
    value     TCPConnection this-TCPConnection
    multiline value         switch             read-to-double-line-end optional initial {false}
    timeout   value         integer       timeout-in-milliseconds optional
as TCPConnectionGetLine


Purpose

This function reads up to and including the next line-end sequence ("%13#%10#", or "%10#), or the next pair of line-end sequences if the multiline value is true, and returns the read characters.

The returned characters are "normalized" as follows:

  1. All line-end sequences are replaced by "%13#%10#".
  2. The trailing line-end sequence in the multiline case is removed, so that there is only one line-end sequence at the end.

If a timeout value is set and then exceeded, either zero characters are returned or only those available, as seems appropriate. The TCP connection object is set to be in error.

Note that difficulties inherent in deriving multiple sources from a connection apply equally to using TCPConnectionGetLine when a TCPConnectionGetSource derived source is also active. However, sequential uses of TCPConnectionGetLine are safe. It is also guaranteed that a TCPConnectionGetLine will only ever read the characters it returns from a source. Any following characters are available to the next TCPConnectionGetSource, TCPConnectionGetCharacters, or TCPConnectionGetLine.

Any attempt to do a TCPConnectionGetLine when the associated TCP connection object has been closed using TCPConnectionClose is in error.

Any attempt to do a TCPConnectionGetLine when there is already an active source derived from TCPConnectionGetSource is not allowed, and will result in an OmniMark external function exception.

Arguments:

Example

  local TCPConnection TCP-Conn
  
  set TCP-Conn to TCPConnectionOpen on "localhost" at 5300
  
  repeat 
     exit unless TCPConnectionIsConnected TCP-Conn
     output TCPConnectionGetLine TCP-Conn
  again