Overview of the Sockets Package
Calling Sequence
Description
List of Sockets Package Commands
Examples
References
Sockets:-command(arguments)
command(arguments)
use Sockets in ... end use
The Sockets package is a suite of tools for network communication in Maple. The commands in this package enable you to connect to processes on remote hosts on a network (such as an Intranet or the Internet) and exchange data with these processes. In particular, it enables two independent Maple processes running on different machines on a network to communicate with one another.
For important notes on network security, see the release notes for this package Sockets,release.
This package presents a user interface to reliable, connection-oriented, stream sockets in the Internet domain (TCP/IP). You can create a client socket by using procedure Sockets:-Open, which enables you to connect to and communicate with a server on a remote machine. You can also create a server socket by using procedure Sockets:-Serve, which enables you to offer computational services to which others can connect and make requests.
The Sockets package automatically shuts down any open connections that it is managing before being garbage collected, or when the Maple process in which it is running terminates normally. However, there is no user control over when this occurs (except in the case of termination), so you should not rely on it to shut down socket connections normally.
For more information about platform support and run-time issues, see Sockets release notes.
Each command in the Sockets package can be accessed by using either the long form or the short form of the command name in the command calling sequence.
The long form, Sockets:-command, is always available. The short form can be used after loading the package.
If you are using these routines for programming, you can access the exports of this package by enclosing your code in a use statement that binds this package; for example, use Sockets in ... end use. See use for more details.
All socket connections created by routines in this package are represented by an opaque type exported as Sockets:-socketID, which is local to the Sockets package. You can test whether an expression expr has the correct structure for a socket ID by using type( expr, Sockets:-socketID ). (Note that the type must not be quoted in this case.)
The following is a list of available commands.
Address
Close
Configure
GetHostName
GetLocalHost
GetLocalPort
GetPeerHost
GetPeerPort
GetProcessID
HostInfo
LookupService
Open
ParseURL
Peek
Read
ReadBinary
ReadLine
Serve
Status
timeout
Write
WriteBinary
To display the help page for a particular Sockets command, see Getting Help with a Command in a Package.
Use with to obtain interactive access to the package procedures.
with⁡Sockets
Address,Close,Configure,GetHostName,GetLocalHost,GetLocalPort,GetPeerHost,GetPeerPort,GetProcessID,HostInfo,LookupService,Open,ParseURL,Peek,Read,ReadBinary,ReadLine,Serve,Status,Write,WriteBinary
Find out where you are on the network.
GetHostName⁡
rdubtroll4.maplesoft.com
Open a connection to the echo server on the peer (a particular machine on the same network as the machine that generated this help page).
with⁡Sockets:
sid≔Open⁡mantis,echo
0
Send a message to the peer.
Write⁡sid,sprintf⁡Hello from %s!\n,GetHostName⁡
37
Read back the response.
Read⁡sid
Hello from rdubtroll4.maplesoft.com!
Shut down the connection.
Close⁡sid
true
The following program finger enables you to make a query by using the finger protocol.
finger := proc( _who ) local who, at, host, sock; who := _who; at := StringTools:-FirstFromLeft( "@", who ); if at <> FAIL then host := who[ 1 + at .. -1 ]; who := who[ 1 .. at - 1 ] else host := "localhost" end if; use Sockets in sock := Open( host, finger ); Write( sock, sprintf( "%s\r\n", who ) ); printf( "%s\n", Read( sock, 5 ) ); Close( sock ) end use; NULL end proc:
For background material on network programming concepts in the Sockets package, see references.
See Also
help
iolib
module
Sockets references
Sockets release notes
use
UsingPackages
with
Download Help Document