Sockets - Maple Help

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

Sockets

 read a line of text from a socket

 Calling Sequence ReadLine(sid, timeout)

Parameters

 sid - valid open socket ID timeout - (optional) non-negative integer; number of seconds to block before timing out

Description

 • Many network protocols are line-based to allow for easy and efficient implementation. For this reason, a separate entry point ReadLine is provided for reading text one line at a time over a socket connection.
 • The procedure ReadLine is similar to the procedure Sockets[Read], however, it stops reading upon encountering the first newline (ASCII 10) character in the data. Like Sockets[Read], the procedure ReadLine is used to read textual data from a socket. It cannot be used to read data containing null bytes. (To read binary data, see Sockets[ReadBinary].)
 • The argument sid must be a valid socket ID for an open socket connection. The optional argument timeout indicates the number of seconds the call to ReadLine should block before timing out and returning the value false.
 • The ReadLine procedure obeys the persistent timeout protocol. (See Sockets/timeout.)

Examples

 > $\mathrm{with}\left(\mathrm{Sockets}\right):$
 > $\mathrm{sid}≔\mathrm{Open}\left("localhost","echo"\right)$
 ${0}$ (1)
 > $\mathrm{Write}\left(\mathrm{sid},"The higher, the fewer!"\right)$
 ${23}$ (2)
 > $\mathrm{ReadLine}\left(\mathrm{sid}\right)$
 ${"The higher, the fewer!"}$ (3)
 > $\mathrm{Close}\left(\mathrm{sid}\right)$
 ${\mathrm{true}}$ (4)
 > $\mathrm{sid}≔\mathrm{Open}\left("mantis","echo"\right)$
 ${0}$ (5)
 > $\mathrm{Write}\left(\mathrm{sid},"The higher, the fewer!"\right)$
 ${23}$ (6)
 > $\mathrm{ReadLine}\left(\mathrm{sid}\right)$
 ${"The higher,"}$ (7)
 > $\mathrm{ReadLine}\left(\mathrm{sid}\right)$
 ${"the fewer!"}$ (8)
 > $\mathrm{Close}\left(\mathrm{sid}\right)$
 ${\mathrm{true}}$ (9)
 > $\mathrm{sid}≔\mathrm{Open}\left("mantis","finger"\right)$
 ${\mathrm{sid}}{:=}{0}$ (10)
 > $\mathrm{Write}\left(\mathrm{sid},"maple"\right)$
 ${7}$ (11)
 > $\mathbf{while}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{line}\ne \mathrm{false}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{line}≔\mathrm{ReadLine}\left(\mathrm{sid}\right);\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{printf}\left("%s",\mathrm{line}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end do}:$
 Login       Name               TTY         Idle    When    Where maple    Maple Development     pts/1         helene               mapledis Maple Distribution                 < .  .  .  . > chickman Maple T.A. Developer               < .  .  .  . > false
 > $\mathrm{Close}\left(\mathrm{sid}\right)$
 ${\mathrm{true}}$ (12)