Module "socket"
This module provides TCP/IP sockets. A socket provides a duplex
binary stream. The read and write stream can be obtained by the
ordinary ISO core standard open/[3,4] predicates. The open options
also apply to sockets so that a binary stream can be easily viewed
as a text stream in various encodings.
Example:
?- client_new('pot.ty', C), open(C, write, S),
write_term(S, 'Hello World!'), nl(S), close(C).
A server socket can be created with the predicates server_new/2.
The predicate server_accept/2 delivers a session socket. A client
socket can be created with the predicates client_new/3. Server,
session and client sockets can be closed with the ISO core
standard close/[1,2] predicates.
The following socket predicates are provided:
- server_new(H, P, S):
- The predicate succeeds in S with a new server socket for the
host H and the port P. A zero port number lets the operating
system choose a port number.
- server_port(S, P):
- The predicate succeeds in P with the local port of the server
socket S.
- server_address(S, H):
- The predicate succeeds in P with the inet address of the
server socket S.
- server_accept(S, H):
- The predicate succeeds in H with a new session socket from
server socket S.
- client_new(H, P, C):
- The predicate succeeds in C with a new client socket for host
H and port P.
- endpoint_new(H, P, S):
- The predicate succeeds in S with a new datagram socket for the
host H and the port P. A zero port number lets the operating
system choose a port number.
- endpoint_port(S, P):
- The predicate succeeds in P with the local port of the
datagram socket S.
- endpoint_address(S, H):
- The predicate succeeds in H with the inet address of the
datagram socket S.
- endpoint_receive(S, B):
- The predicate succeeds in B with the data received from the
datagram socket S.
- endpoint_send(S, B, D, P):
- The predicate succeeds in sending the data B to the
destination host D and destination port P on the datagram socket
S.
Comments