WriteBinary - Maple Help

Sockets

 WriteBinary
 write binary data on a socket connection

 Calling Sequence WriteBinary(sid, a)

Parameters

 sid - socket ID for the socket connection a - rtable with hardware datatype

Description

 • The procedure Sockets[Write] cannot be used to write binary data on a socket connection because Maple strings cannot encode the data. Therefore, the interface WriteBinary is provided to enable you to send binary data onto a socket connection.
 • The first argument is a valid and open socket ID sid on which the data is written. The second argument is an rtable a with a hardware datatype that contains the data you want to write to the socket connection.
 • The rtable a cannot use indexing functions and it must have rectangular storage. The rtable can have any of the following hardware datatypes:

 integer[ 1 ] integer[ 2 ] integer[ 4 ] integer[ 8 ] float[ 4 ] float[ 8 ]

 • If the datatype of a is anything but integer[1], then the data is treated as structured and each "record" is converted to Network Byte Order before being written to the socket.
 • The number of bytes actually written to the socket is returned as a Maple (non-negative) integer.

Examples

 > $\mathrm{with}\left(\mathrm{Sockets}\right):$
 > $\mathrm{sid}≔\mathrm{Open}\left("mantis","echo"\right)$
 ${0}$ (1)
 > $a≔\mathrm{Array}\left(\mathrm{convert}\left("Hello",'\mathrm{bytes}'\right),'\mathrm{datatype}'='\mathrm{integer}'\left[1\right]\right)$
 ${a}{≔}\left[\begin{array}{ccccc}{72}& {101}& {108}& {108}& {111}\end{array}\right]$ (2)
 > $\mathrm{WriteBinary}\left(\mathrm{sid},a\right)$
 ${5}$ (3)
 > $\mathrm{Read}\left(\mathrm{sid}\right)$
 ${"Hello"}$ (4)
 > $\mathrm{Close}\left(\mathrm{sid}\right)$
 ${\mathrm{true}}$ (5)