next up previous contents index
Next: General socket calls. Up: Library Utilities Previous: Notes:   Contents   Index

Socket I/O

The XSB socket library defines a number of predicates for communication over BSD-style sockets. Most are modeled after and are interfaces to the socket functions with the same name. For detailed information on sockets, the reader is referred to the Unix man pages (another good source is Unix Network Programming, by W. Richard Stevens). Several examples of the use of the XSB sockets interface can be found in the XSB/examples/ directory in the XSB distribution.

XSB supports two modes of communication via sockets: stream-oriented and message-oriented. In turn, stream-oriented communication can be buffered or character-at-a-time.

To use buffered stream-oriented communication, system socket handles must be converted to XSB I/O ports using fd2ioport/2 and then the regular low-level file I/O primitives (described in Section 1.5) are used. In stream-oriented communication, messages have no boundaries, and communication appears to the processes as reading and writing to a file. At present, buffered stream-oriented communication works under Unix only.

Character-at-a-time stream communication is accomplished using the primitives socket_put/3 and socket_get0/3. These correspond to the usual Prolog put/1 and get0/1 I/O primitives.

In message-oriented communication, processes exchange messages that have well-defined boundaries. The communicating processes use socket_send/3 and socket_recv/3 to talk to each other. XSB messages are represented as strings where the first four bytes (sizeof(int)) is an integer (represented in the binary network format -- see the functions htonl and ntohl in socket documentation) and the rest is the body of the message. The integer in the header represents the length of the message body.

We now describe the XSB socket interface. All predicates below must be imported from the module socket. Note that almost all predicates have the last argument that unifies with the error code returned from the corresponding socket operation. This argument is explained separately.



Subsections
next up previous contents index
Next: General socket calls. Up: Library Utilities Previous: Notes:   Contents   Index
Luis Fernando P. de Castro 2003-06-27