Admin Production ni-theme
Current Publication

InetTelnetRead

LabWindows/CVI

InetTelnetRead

int InetTelnetRead (int telnetHandle, char readBuffer[], ssize_t bytesToRead, ssize_t *bytesRead, int timeout);

Purpose

Reads data from the Telnet connection and stores it in readBuffer with the Telnet control characters filtered out.

The function returns when bytesToRead bytes, not including the discarded Telnet control characters, have been read or when timeout ms have elapsed.

Returns 0 if successful or a negative error code otherwise.

This function does not return timeout as an error. If a timeout occurs, the return value of the function will be 0. Compare bytesToRead with bytesRead to detect the timeout condition. If they are not equal, a timeout occurred.

Note  InetTelnetRead converts any NUL characters received from the Telnet server into line feeds ('\n' or ASCII decimal value 10). This makes the resulting readBuffer viewable as a string.

Parameters

Input
Name Type Description
telnetHandle int An integer handle identifying the Telnet connection. You can call InetTelnetOpen to obtain this handle.
bytesToRead ssize_t The maximum number of bytes to be read from the Telnet connection.

bytesToRead must be no greater than the size of the readBuffer – 1. For example, if you want to read three bytes from the Telnet connection, set bytesToRead to 3 and make sure readBuffer can hold at least four bytes, which includes one extra byte for the NUL character.
timeout int Timeout in milliseconds.

After timeout ms pass, the function returns without an error. Compare bytesToRead with bytesRead after the function returns to detect a timeout. If they are not equal, a timeout occurred.

Passing –1 for timeout causes InetTelnetRead to read indefinitely for bytesToRead bytes.
Output
Name Type Description
readBuffer char [] The data read from the Telnet connection, with the Telnet control characters filtered out.

readBuffer must be able to hold at least bytesToRead plus one extra byte for the NUL character.

Note  This function converts any NUL characters received from the Telnet server into line feeds ('\n' or ASCII decimal value 10). This makes readBuffer viewable as a string.
bytesRead ssize_t The actual number of bytes successfully read from the Telnet connection.

If this value is less than bytesToRead when the function returns, a timeout occurred.

Passing NULL for bytesRead causes the information to be discarded; however, this makes it difficult to determine whether the function returned because bytesToRead bytes were read or because a timeout occurred.

Return Value

Name Type Description
result int Return value indicating whether the function was successful. A negative number indicates that an error occurred.

Additional Information

Library: Internet Library

Include file: cvintwrk.h

LabWindows/CVI compatibility: LabWindows/CVI 7.1 and later

Example

Refer to internet\telnet\telnet.cws for an example of using the InetTelnetRead function.