Author(s): Manuel Carro, Daniel Cabeza.
Version: 1.5#128 (2000/5/2, 18:4:14 CEST)
Version of last change: 1.5#127 (2000/5/2, 16:50:36 CEST)
This module defines primitives to open sockets, send, and receive data from them. This allows communicating with other processes, on the same machine or across the Internet. The reader should also consult standard bibliography on the topic for a proper use of these primitives.
sockets
):- use_module(library(sockets)).
sockets
)
Usage: connect_to_socket(+Host,+Port,-(Stream))
connect_to_socket_type/4
with SOCK_STREAM connection type. This is the connection type you want in order to use the
write/2
and
read/2
predicates (and other stream IO related predicates).
+Host
is an atom.
(basic_props:atm/1
)
+Port
is an integer.
(basic_props:int/1
)
-(Stream)
is an open stream.
(streams_basic:stream/1
)
Usage: socket_recv(+Stream,?(String))
Defines the atoms which can be used to specify the socket type recognized by
connect_to_socket_type/4
. Defined as follows:
socket_type(stream). socket_type(dgram). socket_type(raw). socket_type(seqpacket). socket_type(rdm).
Usage: socket_type(T)
T
is a valid socket type.
Usage: socket_recv_code(+Stream,?(String),?(Length))
String
from the socket associated to Stream
, and returns its Length
. If Length
is -1, no more data is available.
+Stream
is an open stream.
(streams_basic:stream/1
)
?(String)
is a string (a list of character codes).
(basic_props:string/1
)
?(Length)
is an integer.
(basic_props:int/1
)
Usage: socket_send(+Stream,+String)
String
to the socket associated to Stream
. The socket has to be in connected state. String
is not supposed to be NULL terminated, since it is a Prolog string. If a NULL terminated string is needed at the other side, it has to be explicitly created in Prolog.
+Stream
is an open stream.
(streams_basic:stream/1
)
+String
is a string (a list of character codes).
(basic_props:string/1
)
Usage: select_socket(+Socket,-(NewStream),+TO_ms,+Streams,-(ReadStreams))
+Socket
is an integer.
(basic_props:int/1
)
-(NewStream)
is an open stream.
(streams_basic:stream/1
)
+TO_ms
is an integer.
(basic_props:int/1
)
+Streams
is a list of stream
s.
(basic_props:list/2
)
-(ReadStreams)
is a list of stream
s.
(basic_props:list/2
)
Usage: socket_accept(+Sock,-(Stream))
Stream
connected to Sock
.
+Sock
is an integer.
(basic_props:int/1
)
-(Stream)
is an open stream.
(streams_basic:stream/1
)
Usage: bind_socket(?(Port),+Length,-(Socket))
Socket
bound to Port
(which may be assigned by the OS or defined by the caller), and listens to it (hence no listen call in this set of primitives). Length
specifies the maximum number of pending connections.
?(Port)
is an integer.
(basic_props:int/1
)
+Length
is an integer.
(basic_props:int/1
)
-(Socket)
is an integer.
(basic_props:int/1
)
Usage: connect_to_socket_type(+Host,+Port,+Type,-(Stream))
Stream
which connects to Host
. The Type
of connection can be defined. A Stream
is returned, which can be used to
write/2
to, to
read/2
, to
socket_send/2
to, or to
socket_recv/2
from the socket.
+Host
is currently instantiated to an atom.
(term_typing:atom/1
)
+Port
is an integer.
(basic_props:int/1
)
+Type
is a valid socket type.
(sockets:socket_type/1
)
-(Stream)
is an open stream.
(streams_basic:stream/1
)
Go to the first, previous, next, last section, table of contents.