Examples

Five examples have been provided in IPC/TCP/demo. Each example has detailed instructions on its use in its source file. A Makefile is provided in the demo directory.

Calling absolute_file_name/2 is a convenient way of finding the path to a demonstration program. For example, to find the sibling demonstration, try issuing the command

     | ?- absolute_file_name(demo('sibling.pl'),X).
     

Here is a list of the example tcp programs.


client.pl, server.pl
The client/server example. This illustrates how connections are established and a very simple method of remote procedure call.
sibling.pl
This file demonstrates the tcp software for three connected processes. Once connected, all three send and receive goals to each other as peers. It can detect reception of keyboard input, since it uses the tcp_watch_user/2 predicate.
ce.pl
An example of the producer, filter, consumer problem. The producer process sends random numbers between 0 and 1 to the filter process, which in turn sends copies of the numbers it received from the producer ranging between 0.2 and 0.7 to the consumer.
cs.c
This is a simple way to call the Prolog server defined in server.pl from the c-shell. If the ServerFile (see tcp_address_from_file/2, ipc-tcp-mco-address_from_file2) for some server is x, then
          % cs x "write('hi there'),nl"
          

causes the server to write the string "hi there\n" to its socket. The C program cs.c copies the socket output from the server to stdout.

c_server.c, c_server.pl
This illustrates a Prolog client calling a C server.