Sockets 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 the library asock.plm with a compiled Prolog program.

The samples:

Finger Sample

The simplest program to finger a host. If you are running under Unix you will need to change the sdefine/2 declaration at the top and comment out the Windows calls (wsaStartup and wsaCleanup).

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 Sample

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. If you are running under Unix you will need to change the sdefine/2 declaration at the top and comment out the Windows calls (wsaStartup and wsaCleanup).

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 crtl-C/break out of the server.