| Online Eiffel Documentation

EiffelStudio

# The predefined level

Many client-server applications follow a standard scheme that relies on the facilities outlined so far. When your application conforms to this scheme, you can avoid most of the work by relying on the client and server classes of the predefined level. There is no need to consider sockets explicitly or to worry about synchronization.

As in many other cases found in the Eiffel Software's libraries, the object-oriented method makes it possible here to encapsulate the standard pattern found in most usual cases.

### The predefined client and server classes

The classes of the predefined level, which only support stream communication (not datagrams), are CLIENT, SERVER, and their descendants UNIX_CLIENT, UNIX_SERVER, NETWORK_CLIENT and NETWORK_SERVER. All the architecture of a client-server application is already available through these classes. All you have to do is to specify the address you want to use, what you want to send, when you want to send it, and what you want to do when you receive data. The rest will be taken care of automatically.

The UNIX_classes are meant for systems running on the same machine, using UNIX_STREAM_SOCKET; the NETWORK_classes support inter-machine communication, usingNETWORK_SOCKET.

### Using the client classes

When you want to write an application, your client should inherit from UNIX_CLIENT for example, and in your creation procedure, you have to setup your address, and then call the inherited make routine, with your address as an argument. You are then provided with some send and receive routines.

### Using the server classes

For the server, you inherit for example from UNIX_SERVER. In the same way as for the client, you set up your address in the creation procedure, and then call themake creation procedure inherited fromUNIX_SERVER. After that your creation procedure should callexecute, which is inherited fromSERVER, and provides you with a loop callingreceive,process_message,respond andclean_up. Then, you should redefine these routines to do what you want your server to do.