Tcp Socket Survey System

Project Outline

In the project, I used socket API provided by linux system library, to construct a survey system. The socket library provides basic API which can create a socket, listen to and accept connection, send and receive data.
I used these basic functions to build more friendly and convenient functions, for example, transmiting an integer, transmiting a string, and so on.

In the survey server program, it first create a socket object with a fixed port number, and then listen to the port, if a survey clinet tries to connect to the port, then the server accept the connection. After that, the survey server starts to send questions to the client, and waits for the response from the client. To serve multiple clients, the servey server need to creates a seperate thread for each client, because each client should be served concurrently. Also, every thread need to use a mutex object to protect the critical section, because all threads write to a shared memory which records the information of the survey. In the project, I used pthread library to create threads and achieve mutual exclution.

I use pthread_t to create a new thread, and use the function thread_create to assign the procedure and a parameter to the new thread.
I use pthread_mutex to create a mutex object, and use pthread_mutex_lock & unlock to control the critical section.


Survey Server
Survey Client
Survey Common

Reference — Socket APIs

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License