This project demonstrates network socket programming in C by implementing a multi-threaded server and a client application. The server listens for incoming connections, handles multiple clients simultaneously using multi-threading, and provides an interface for users to manage an address book database. Clients can log in, search, add, update, or delete records, and even retrieve a list of active users. The system also supports administrative commands, including server shutdown.
The primary objective of this project is to explore:
- Networking concepts like socket creation, connection handling, and message passing over TCP.
- Multi-threading for concurrent handling of multiple clients.
- User authentication and session management.
- File I/O operations to persistently store and retrieve data from an address book.
- Inter-process communication (IPC) through sockets for efficient data transfer.
This project is useful for understanding real-world client-server architectures used in networking applications, database services, and distributed systems.
- Multi-threaded server that handles multiple clients simultaneously.
- Client-server communication over TCP sockets.
- User authentication with login and logout functionality.
- Address book management (lookup, add, delete, update records).
- Graceful client disconnection and server shutdown support.
Socket_Programming/
│── multiThreadServer.c # Multi-threaded server implementation
│── sclient.c # Client program to connect to the server
│── addressbook.txt # Sample data file storing address book records
│── Makefile # Makefile to compile the project
│── README.md # Project documentation
To compile the server and client programs, use the provided Makefile:
makeThis will generate the following executables:
multiThreadServersclient
Alternatively, compile manually using:
gcc -pthread -o multiThreadServer multiThreadServer.cgcc -o sclient sclient.cRun the server on a machine:
./multiThreadServerThe server listens on port 8080.
On another terminal or machine, connect a client to the server:
./sclient <server_ip>Example:
./sclient 127.0.0.1Once connected, clients can send commands:
- LOGIN
<user_id><password>- Authenticate a user. - LOGOUT - Log out from the session.
- LIST - View all address book entries.
- LOOK
<type><query>- Search records by first name, last name, or phone number. - ADD
<first_name><last_name><phone_number>- Add a new record. - DELETE
<record_id>- Remove an entry. - UPDATE
<record_id><field><new_value>- Update a record. - WHO - List active users.
- QUIT - Disconnect the client.
- SHUTDOWN - Shut down the server (Admin only).
Enter command: LOGIN john john06
Server: 200 OK
Enter command: LIST
Server: 200 OK
1001 John Doe 123-456-789
Enter command: QUITServer started on port 8080
New connection from 127.0.0.1 on socket 4
Received from socket 4: LOGIN john john06
User 'john' logged in.
Received from socket 4: LIST
Sent address book data to client.
Received from socket 4: QUIT
Client on socket 4 disconnected.To remove compiled binaries:
make cleanThis project is licensed under the MIT License.