Sockets
ReadBinary
read binary data from a network connection
Calling Sequence
Parameters
Description
Examples
ReadBinary(a, sid)
a
-
rtable with hardware datatype
sid
valid open socket ID
Because Maple strings are incapable of encoding binary data (containing null bytes), an interface different from Sockets[Read] is required for applications that need to be able to transmit such data. This is achieved by using procedure ReadBinary.
The first argument a to procedure ReadBinary must be a hardware rtable; that is, one whose datatype is one of the following:
integer[ 1 ]
integer[ 2 ]
integer[ 4 ]
integer[ 8 ]
float[ 4 ]
float[ 8 ]
The rtable a should not use any indexing functions and the storage parameter should not be set to anything other than rectangular.
If the datatype is anything other than integer[1], then the data to be read is treated as structured according to the indicated datatype and each ``record'' is converted to the host byte order. For example, passing an rtable whose datatype is float[4] causes each four-byte float to be converted from Network Byte Order to Host Byte Order.
ReadBinary accepts a socket ID sid as its second argument. Parameter sid indicates the network connection from which to read the data.
ReadBinary attempts to read as much data from the socket connection as it can, up to the total amount of space available in the rtable a. The number of bytes actually read is returned.
Note: There may be more data available on the socket than can be accommodated in the rtable passed to ReadBinary. Once the rtable has been filled, ReadBinary returns, leaving any unread data on the socket for subsequent calls to consume.
It is also possible that there is insufficient data available on the socket to fill rtable a.
with⁡Sockets:
s≔Open⁡localhost,echo
0
Write⁡s,Hello
5
a≔Array⁡1..10,datatype=integer1
a≔0000000000
ReadBinary⁡a,s
7210110810811100000
convert⁡convert⁡a,list,bytes
Hello
Close⁡s
true
The time service (RFC 868) delivers the current time (measured as the number of seconds since 00:00 (midnight) 01 January 1900) as a 32-bit integer in Network Byte Order.
s≔Open⁡mantis,time
a≔Array⁡1..4,datatype=integer4
a≔0000
4
a1
1608616937
See Also
rtable
socket definition
Sockets/timeout
Sockets[Read]
Sockets[WriteBinary]
Download Help Document