sockets - internet samples

Two things are required to run any sockets program from Prolog:

  1. Load asock.lsx. One way is to include lsxload = asock in the amzi.cfg file.
  2. Load asock.plm. This can be done with a load(asock) goal in a Prolog program, or it can be done by linking asock.plm with a compile Prolog program.

The samples:

finger

The simplest program to finger a host. To run it from the listener:

?- load(asock).
yes
?- consult(finger).
yes
?- main.
Host name to finger? %enter the host name
...

You should see the address echoed and then a request for a login ID, which if you have one, should then lead to some more information.

client/server

A simple client/server example, where the clients send lines of text to the server, which echos the text. It can be run on one machine or multiple ones. To run on a single machine, open two consoles and run alis in each.

server

?- load(asock).
yes
?- consult(sserver).
yes
?- main.

client

?- load(asock).
yes
?- consult(sclient).
yes
?- main.
Send what? hello
yes
?-

The server should then echo the 'hello'. From the client, type main again and send the string 'shutdown' to shut down the server. Or you can just cntl-C/break out of the server.