read binary data from a network connection - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Connectivity : Web Features : Network Communication : Sockets Package : Sockets/ReadBinary

Sockets[ReadBinary] - read binary data from a network connection

Calling Sequence

ReadBinary(a, sid)

Parameters

a

-

rtable with hardware datatype

sid

-

valid open socket ID

Description

• 

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.

Examples

withSockets:

s:=Openlocalhost,echo

0

(1)

Writes,Hello

5

(2)

a:=Array1..10,'datatype'='integer'1

a:=0000000000

(3)

ReadBinarya,s

5

(4)

a

7210110810811100000

(5)

convertconverta,'list','bytes'

Hello

(6)

Closes

true

(7)

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:=Openmantis,time

0

(8)

a:=Array1..4,'datatype'='integer'4

a:=0000

(9)

ReadBinarya,s

4

(10)

a1

107835688

(11)

Closes

true

(12)

See Also

rtable, socket definition, Sockets, Sockets/timeout, Sockets[Read], Sockets[WriteBinary]


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam