Next: 6.2 Client/server programming: Linda
Up: 6 The Web of
Previous: 6 The Web of
We have tried to hide socket operation as well as possible from
the Prolog programmer, usually interested in elegant, high-level
programming. Some inspiration from Java's approach to socket
programming is gratefully acknowledged.
-
new_client(Host,Port,ClientSocket) creates ClientSocket connected to
Host (a remote computer's Internet address, by default localhost),
Port (a Unix port, by default 9001)
- new_server(Port,ServerSocket) opens on Port (by default 9001)
a new ServerSocket
- new_service(ServerSocket, Timeout, ServiceSocket)
creates a ServiceSocket answering ServerSocket within Timeout seconds
- close_socket(Socket) closes a server, service or client socket
- sock_read(Socket,CharList) reads a list of characters from a
socket. Internally, the length in bytes is sent as 32 bit network-ordered
word is read, then the bytes which are converted to a Prolog list
of character codes.
- sock_readln(Socket,CharList) reads a list of characters from a socket, allowing the programmer to internalize it with name/2. Note that
internalizing is better to be avoided as it fills internal tables
which are garbage collected only when restart/0 resets them together
with all dynamic data. However, term_chars/2 allows extracting
a term from such a list of chars without internalizing it.
- sock_write writes a list of characters
to a socket, first its length in bytes then as a sequence of bytes.
- sock_writeln writes a list of characters
to a socket, terminated with a newline character. Both sock_read(ln) and
sock_write(ln) are intended to be used in `connectionless' ask/answer
style dialog between a client and a server (see the Linda package in file extra.pl built on top of them as an example of use.
- sleep(N) waits N seconds without using CPU resources
- fork(Pid) starts a new completely IO-less background Unix process (child) with stdio, stdout and stderr redirected to /dev/null and returns
the child's Pid to the parent and Pid=0 to the child
Next: 6.2 Client/server programming: Linda
Up: 6 The Web of
Previous: 6 The Web of
Paul Tarau
Thu Apr 3 10:26:39 AST 1997