The C functions

Communication between processes is effected through sockets. Sockets are referred to by small 32 bit integers, called file descriptors below (even though they are proper file descriptors only under UNIX).

The program using this package should be linked with the object file tcp_c.o (substitute the actual object file extension for .o). The sources to create this file, the C source files tcp.c and tcp.h, are provided in the tcp library directory.1 Furthermore, the source file tcp.h from IPC/TCP should be included in the C sources using the package.

Errors from using the C tcp package are written to stderr using the system function perror(3), so whenever a tcp C function indicates an error, the error message has already been printed and errno has already been set.

Although sockets may be used like any other file descriptor, they must be killed using tcp_shutdown(), otherwise the behavior of tcp_select() will become unpredictable.

For a C client calling a Prolog server, see example cs.c (ipc-tcp-exa).

For a Prolog client calling a C server, see example, c_server.c (ipc-tcp-exa).


  1. The object file is also created in the system directories of tcp at installation time. In the development system, the call absolute_file_name(library(system('tcp_c.o')),AbsPath) returns the full path to the object file tcp_c.o for the particular architecture being used.