Cluster lib/net

  Networking: client-side and server-side sockets.
  ->See description

ACCESS

Access to a server running on some host (at some address).


 
ADDRESS

The address of a host.


 
SOCKET_ERRORS

Access to error messages.


 
SOCKET_INPUT_OUTPUT_STREAM

A stream backed by a socket.


 
SOCKET_SERVER_JOB

Encapsulate the server in a sequencer-aware job.


 

->

Description

Networking: client-side and server-side sockets.

How to use the "net" cluster

This page is divided into the following sections:

Vocabulary

Access A word used by this cluster to design a server access on a host.
Address A word used by this cluster to design a host.
Host A machine connected to a network. Such a machine has an address and, usually, a name.
Server A program that runs on a host. Such a programs listens on a "port number".

Be a Client

To be client means trying to reach some server and getting some data from it.

There are two concepts to grasp before making a connection:

  • Address: that's the network address of a machine (a "host"), given either by its name or its IP number. The net cluster knows of three kinds of addresses: the host name, the IP address and the local address which represents the local machine.
  • Access: it allows to connect to some server that runs on a machine and listens on a port. The net cluster knows of three kinds of accesses: TCP and UDP access, and the special Local access that reaches the local machine.
  • To be a client, you have to do three things, in that order:

    In SmartEiffel, you would write it this way:

       connect_to_funet: TERMINAL_INPUT_OUTPUT_STREAM is
          local
             funet: HOST
             tcp: TCP_ACCESS
          do
             create funet.make(once "ftp.funet.fi")
             create tcp.make(funet, 21)
             Result := tcp.stream
          end
    

    (See also the tutorial: class SOCKETS)

    Be a Server

    To be a server, things are a bit more complex but not tremendously so.

    First note that you must know something of the lib/sequencer cluster. You must also be familiar with agents.

    To create a server, start by creating an address and an access. The address will filter which connections are allowed1, and the access port will determine which port the server will listen to.

    Now you must create a SOCKET_SERVER, give it one or more agents using the `when_connect' feature. Those agents are called whenever a new client connects; each agent is given the same stream that represents the connection to the client.

    Note that having multiple agents is potentially dangerous. Either all the agents cooperate, either having one registered is enough. Remember that all agents share the same stream.