next up previous index
Next: Datagram Connection on a Up: Interprocess Communication Previous: Socket Domains   Index

Stream Connection on a Single Machine

This type of communication is very similar to pipes, the stream communication is reliable and there are no boundaries between the messages. Stream sockets always require explicit connection from both communicating processes.

After a socket is created with the socket/3 predicate, one of the processes, the server, gives it a name and waits for a connection. The other process uses the same name when connecting to the former process. After the connection is established, both processes can read and write on the socket and so the difference between the server and the client disappears:

server:
    [eclipse 10]: socket(unix, stream, s), bind(s, '/tmp/sock').

    yes.
    [eclipse 11]: listen(s, 1), accept(s, _, news).
    <blocks waiting for a connection>

client:
    [eclipse 26]: socket(unix, stream, s), connect(s, '/tmp/sock').

    yes.
    [eclipse 27]: printf(s, "%w. %b", message(client)), read(s, Msg).

server:
    [eclipse 12]: read(news, Msg), printf(news, "%w. %b", message(server)).

    Msg = message(client)
    yes.

client:
    Msg = message(server)
    yes.




1999-08-06