Progress
External Program
Interfaces
Reading Data On a Socket
To read data from a connected TCP/IP socket, you invoke the READ( ) method on the corresponding socket object (SELF:READ( ) within the corresponding READ-RESPONSE event procedure). You can invoke this method on a connected socket at any time to read data. However, the method blocks depending on the amount of data available on the socket, the reading mode that you use, and the timeout value (set by the SO-RCVTIMEO option of the SET-SOCKET-OPTION() method).
The syntax of the READ( ) method follows:
The READ( ) method transfers data from the socket to the specified MEMPTR variable, memptr-expression, at the byte position in the MEMPTR region specified by the INTEGER expression, position. Exactly how much data the READ( ) method blocks to read depends on:
Specifying the Read Mode
You can specify mode using a compiler constant as shown in Table 10–3.
Thus, you can have the READ( ) method block until exactly the specified number of bytes are read (the default), or until all available bytes are read up to a maximum number allowed.
The appropriate reading mode to use depends on your application requirements. Note, however, that if you specify READ-EXACT-NUM, the READ( ) method blocks until it reads the specified number of bytes (no matter how long it takes) or until the socket is disconnected (whatever happens first).
Specifying the Timeout Length
Besides setting the read mode, you can also set the amount of time READ() waits before timing out. To do so, use the SO-RCVTIMEO option of the SET-SOCKET-OPTION() method. If you do not set a timeout value, the default is for READ() to wait forever.
READ()’s timeout behavior is affected by the interaction of the read mode and the timeout value, as Table 10–4 illustrates.
Verifying the Number Of Bytes Actually Read
You can verify the number of bytes actually read by the READ( ) method. The number of bytes read by the last READ( ) method invoked on a socket object is equal to the value of the BYTES-READ attribute invoked on the same socket object.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |