read text data from a socket connection - Maple Help

Online Help

All Products    Maple    MapleSim


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

Sockets[Read] - read text data from a socket connection

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:

sid:=Openmantis,echo

0

(1)

data:=opconvertHi,'bytes',0,opconvertthere,'bytes'

data:=72,105,0,116,104,101,114,101

(2)

datalen:=nopsdata:

data:=Arraydata,'datatype'='integer'1

data:=721050116104101114101

(3)

WriteBinarysid,data

8

(4)

Readsid

Hi

(5)

WriteBinarysid,data

8

(6)

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

a:=00000000

(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]


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