tcpRead()
Reads the data of a defined socket, which was opened with tcpOpen().
Synopsis
int tcpRead(int socket, string/blob &data, time maxTimeout);
Parameters
Parameter | Description |
---|---|
socket | Number of the socket (to which the function tcpOpen established a connection). |
data | Data to be read. If you use a string and the data contains 0 bytes, the function replaces each of the 0 bytes by "." and the log viewer shows a message. |
maxTimeout | Time range the function waits for the data. |
Return value
0 if the function starts correctly (the timeout starts), in case of parameter errors -1. You can retrieve errors by using getLastError().
Error
Missing or wrong arguments.
Description
Reads the data of the defined socket that was opened using tcpOpen(). The system waits maxTimeout for the data. The function tcpRead() is a waiting function and blocks the CTRL thread during the timeout or until the function could read the data. If the function cannot read the data or in case of a timeout, the content of the buffer is undefined.
Example
Opens the connection to a TCP/IP Server socket via tcpOpen() and reads the data of the opened socket via tcpRead().
main()
{
int read, open;
time maxTime;
string data;
time maxTime = 100;
unsigned port;
port=120;
open=tcpOpen("eiwnt094", port);
DebugN(open);
read=tcpRead(open, data, maxTime);
DebugN(data);
}
Assignment
Communication functions, waiting CTRL function
Availability
CTRL