data$, count, done = ReceiveData(id, mode, ...) data$, count, done = ReceiveData(id, #RECEIVEBYTES, maxbytes[, callback, userdata]) data$, count, done = ReceiveData(id, #RECEIVEALL[, untilterm, callback, userdata]) data$, count, done = ReceiveData(id, #RECEIVELINE[, callback, userdata])
OnConnectevent handler which you can set up by calling InstallEventHandler().
The second argument specifies how much data you want to receive from the sender with this call. Currently, the following modes are supported:
ReceiveData()will then never obtain more bytes than you specified. However, it can happen that less bytes are returned in case there is not enough data available from the sender. You can find out the number of bytes obtained by looking at the second return value.
untiltermis set to
ReceiveData()will not return before the sender terminates the connection, thus allowing you to receive all data a sender has to offer using just a single call. If
untiltermis set to
ReceiveData()will only return the data that is currently available. It will not wait for additional data to arrive, but it will tell you if there is more data to be retrieved (in the third return value). The default setting for
Truewhich means that
ReceiveData()will read data until the sender terminates the connection.
ReceiveData()if you use
ReceiveData() returns three values: The first return value is a string
that contains the data that was received from the network or an empty
string if you use a callback to handle the data or no data could be read.
Please note that although the data read is returned as a string, it is not
limited to text only. It can also contain binary data because Hollywood strings
can handle control characters and the
NULL character just fine. The second
return value specifies how many bytes could be read from the network buffer. If this
is 0, then there is currently no data available. The third return value
is only useful if you use
#RECEIVEALL transfer mode with
False. In that case, the third return value tells you if more data is
available in the network buffer. If there is more data to be read, then
False, otherwise it will be
Starting with Hollywood 6.0 there is an optional
that allows you to pass a callback function that should receive the
data read from the server. This can be useful if you need to stream
large amounts of data that cannot be efficiently stored inside a
Hollywood string. The callback function could simply write the data
it receives to a file, for example. Note that if you specify a callback
ReceiveData() will always return an empty string. The callback
function you specify will be called with a single argument: A table that
contains more information. Here is an overview of the table fields that
will be initialized before
ReceiveData() runs your callback function:
The callback function of type
#RECEIVEDATA_PACKET should normally return
False. If it returns
ReceiveData() will abort its operations and
Finally, there is another optional argument called
userdata. The value
you specify here is passed to your callback function whenever it is
called. This is useful if you want to avoid working with global variables.
userdata argument you can easily pass data to your callback
function. You can specify a value of any type in
strings, tables, and even functions can be passed as user data.
#RECEIVEALLis used together with