You are here

TutorialLibraryTest ApplicationDownload
TutorialLibrary[Test Application]Download

Socket Test Applicaiton

The test application of libSock library can be downloaded in the download area of this page. Its installation simply requires to extract files from the archive into the directory of your choice. The Sources folder contains the application's source code, along with a sub-folder /libSock containing the header files to use with the library.

The archive also contains two folders enabling to compile either from Windows (Visual Studio) or Linux (makefile).

Compilation under Linux

Compiling the test application requires that the socket library is already installed on the machine. The installation procedure is described in section Library of this page.

The test application can be built once LibSock is compiled and installed. To do this, extract the testScok archive in the directory of your choice and open a console in the subdirectory /Linux. The compilation command is:

  • make -f testSock.mk all

Compilation under Windows

The Visual Studio project in the /Windows directory enables to compile easily the library. This folder also contains a ready to use libSock library in binary form. libSock.dll is the binary containing the code while libSock.lib contains the declaration of all exported functions of the library. This file has to be included in the project so that the linker can work properly.

Description

Once launched, the test application creates three tasks. The first simulates a server to which 2 clients can connect to. The other 2 tasks simulate these clients. The three tasks are running in parallel and use the different library functions described in this tutorial. Although clients and servers generally run in separate programs and separate machines (networked), we chose here to do everything the same application. Indeed, an application can legitimately create a listening socket and then connect itself with another socket. This is what we do here in order to simplify the implementation of the test program. The IP address to use to connect to itself is "127.0.0.1".

The task which acts as a server first creates a server listening on port 5000. Then it waits for exactly 2 client connections. As soon as connections are established, the server waits for clients requests. These are very simple, but illustrate well a client-server architecture. A request consists in 3 fields. The first 2 fields are integers with which a mathematical operation must be computed . The third field is an integer that describes the operation to be performed. In this example, operations can either be an addition or a multiplication. Once the message is read, the server computes the result and returns it to the client. The task stops when both clients are disconnected.

Architecture client-serveur;

It is clear that in practice it is much easier to realize the sum or multiplication of two numbers ourselves rather than making the request to a server that will make it for us. However, this example aims to be more didactic than convenient by illustrating the types of mechanisms implemented in a client-server architecture. In practice, a server enables to do things that you can not / do not want to do yourself, so it's a service provider. This may be to view data that you could not access otherwise (as you are doing right now by accessing the server hosting this site).