UNIX / LINUX based Client & a Server application

Okey so am writing after some time about some valuable thing !! This is about some thing I happened to do as an assignment for one of my degree modules (Network Application Development). The Assignment is to implement a server and a client using both TCP and UDP. The functionalities expected were, a centralized server which keeps records of the online connected buddies in the network (Subscription)

A Client to communicate and retrieve the buddy list from the central central server and directly connect to the buddy (peer 2 peer)

message broadcasting among groups.

So here I go with some details about the application level protocol and I will atach the C codes if any one needs to download and modify please feel free.

Application Level Protocol

The application level protocol is mainly implements two applications, the central server and the p2p

Basic functionality of the central server

  • User(client) subscription
  • Keep records of the users
  • Update records on new subscription and un-subscription
  • Broadcast the record table to all the online clients.

Basic p2p client functionality

  • Retrieve the user table from the central server.
  • Broadcast messages to all peers
  • Talk with each peer separately

Server protocol

Centralized server is using a TCP connection to connect to all its peers. The Server binds to a socket
and keeps listening to all incoming TCP connections.
When a new client is connected to the server’s port number server accepts the client connection and
open up a new thread for that client.
The server maintains a table of clients containing client information.
In side the newly created thread the server updates the count of clients and inserts new client data in
to its table.
The connection between the server and the client will not be closed.
The server in its main process will keep on listening to new incoming TCP connections.
The server is declaring a thread pool (an array of threads) where it will create a separate new thread
for each connected client and will do all the communication with that client in that separate thread.
The server keeps the number of clients and the client table as global data. And they are shared with
each thread.
As soon as the numbers of clients are changed (a user is newly subscribed or unsubscribed)
server will send the updated table of clients to all clients using the connected threads.

p2p Client protocol

Client connects to the server using a TCP connection.
Client is maintaining UDP server and a UDP client for the peer-to-peer
At first when the client is run with the server port as a command line argument it prompts for the
UDP port where it’s UDP server will be listening for incoming messages from the fellow peers. The
UDP server Port will be send to the central server for subscription.
A child process will be invoked inside the main process for UDP activities (UDP server and client)
The UDP client will prompt for the host address and the port of the fellow peer to start a
conversation. This can be provided by referencing to the clients table, sent by the server.
Then the UDP client will establish a connection with the fellow peer using the given host addresses
and the port.
If a message has to be broadcast the UDP client will connect to all hosts and send the message.

Download the C code, make and run


2 thoughts on “UNIX / LINUX based Client & a Server application”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s