Error getting tags :
error 404Error getting tags :
error 404 read from socket | revDocs | RunRev
Welcome Guest (Log in)
Product Edition
read from socket
Expander triangle

read from socket socketID [until string | for amount [chunkType]] [with message callbackMessage]

Desktop, Web and Server
Platform Support
MacOS,Mac OS X,Windows,Linux
None required
Accepts data from a socket and places the data in the it variable.

read from socket "" -- reads next character
read from socket "" for 50 -- reads next 50 chars
read from socket "|foo" until linefeed
read from socket mySocket for 30 uInt2s with message "gotData"

Additional Comments
Expander triangle

Use the read from socket command to get data from another system via a TCP socket.


The socketID is the identifier (set when you opened the socket) of the socket you want to get data from.

The socket identifier starts with the IP address of the host the socket is connected to, and may optionally include a port number (separated from the IP address by a colon). If there is more than one socket connected to that host and port, you can specify which socket by appending the connection name or number that was assigned when the socket was opened, separated from the port number by a vertical bar (|).

The string is any expression that evaluates to a string. When Revolution encounters the string in the socket data, it stops reading. If the string is not encountered, the read from socket command continues reading as long as there is data to be read.

The amount is a positive integer and specifies how much data to read.

The chunkType is one of chars, characters, words, items, lines, int1, uInt1, int2, uint2, int4, or uint4. The read from socket command reads amount of the specified chunkType. If you don't specify a chunkType, amount characters are read.

The callbackMessage is the name of a message to be sent when the read is successfully completed.


The socket to read from must be opened first with the open socket command. If the socket is not open, the result function is set to "Socket is not open.".

The until string form reads data until the specified string is encountered. The for amount form reads data until the specified number of chunks have arrived. If you don't specify a string or amount, the read from socket command reads the next character of data from the socket.

If you specify a callbackMessage, the message is sent to the object whose script contains the read from socket command, as soon as the read is finished. This message has two parameters: the socketID and the data received from the socket.

If you don't specify a callbackMessage, the handler pauses until the read has been completed, or until the time set in the socketTimeoutInterval property has passed. The data is placed in the it variable after reading. If you specified a binary data chunkType (int1, uInt1, int2, uint2, int4, or uint4), the data consists of a comma-separated list of numbers, one for the numerical value of each chunk that was read. Otherwise, the data is placed in the it variable as it appears in the incoming data stream.

User Comments
Expander triangle
User thumbnail
Feb 27, 2010
Two undocumented aspects of socket reads:
1) "read ... until string" Often packets are terminated with a NULL, but using the NULL character simply causes the read to terminate if there are no characters waiting. If you need to take action on NULL, it seems you must "read ... for 1" and manually check each character. This seems to be more of a bug than a feature, but fixing it now would break code that depends on it.
2) "read for 0" The manual says the numeric argument must be a positive integer, but since the days of MetaCard "read for 0" reads until there are no more characters to read. Roughly this corresponds to the data in a single recv(), so large packets might not transmit in a single send-recv transaction.