Read - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Sockets

  

Read

  

read text data from a socket connection

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

Read(sid, timeout)

Parameters

sid

-

valid open socket ID

timeout

-

(optional) non-negative integer; specify a timeout in seconds

Description

• 

The procedure Read is used to read textual data in the form of Maple strings from a socket connection.

• 

The argument sid must be a valid socket ID for an open socket connection. An optional timeout argument can be passed, which is taken to be the number of seconds to wait before timing out the read operation.

• 

When called, Read blocks indefinitely until data becomes available on the socket sid at which time the available data (up to a system dependent maximum number of bytes) is read. Data read from the socket is returned as a Maple string. If called with the timeout parameter and no data becomes available on the socket sid within the specified number of seconds, then the Read operation returns false.

• 

Calls of the form Read( sid, 0 ) immediately return the value false.

• 

Because Maple strings cannot contain null bytes, Read should be used only when you are sure that the data coming in over the network consists of plain ASCII text. (This is frequently the case.) If data may contain null bytes, then you should use Sockets[ReadBinary] instead.

• 

The Read procedure obeys the persistent timeout protocol. (See Sockets/timeout.)

Examples

This example illustrates how data may appear to be lost if it contains null bytes.

withSockets:

sidOpenmantis,echo

0

(1)

dataopconvertHi,bytes,0,opconvertthere,bytes

data72,105,0,116,104,101,114,101

(2)

datalennopsdata:

dataArraydata,datatype=integer1

data721050116104101114101

(3)

WriteBinarysid,data

8

(4)

Readsid

Hi

(5)

WriteBinarysid,data

8

(6)

aArray1..datalen,datatype=integer1

a00000000

(7)

ReadBinarya,sid

8

(8)

a

721050116104101114101

(9)

Closesid

true

(10)

The underlying problem is that Maple strings cannot contain null bytes.

convertdata,list

72,105,0,116,104,101,114,101

(11)

convert,bytes

Hi

(12)

See Also

socket definition

Sockets

Sockets/timeout

Sockets[ReadBinary]

Sockets[ReadLine]