- Language used: C++14
- Libraries used:
- netinet/in.h - For using the IPv4 macros
- sys/socket.h - For using socket functions
- sys/types.h
- unistd.h - for sleep and other functions
- The server mimics the role of a router
- Clients can dynamically register or leave the router
- The clients are monitored using the select() method
- The clients can communicate in the following ways:
- To get the list of active clients in the network
- LL
- To send ARP request to the server
- AQ { IP of destination client device }
- To send a normal message to a client through the server
- NN { destination client ID } { the message }
- To get the list of active clients in the network
- Uses PORT 8080 for communication
- Uses pthreads for concurrent read operations by clients and server
- Linux Ubuntu Operating System
- G++ Compiler
- PORT 8080 open in the system
- pthread library for Multithreading
- MainServer.cpp
- This is the main file that is to be run to get the server started
- Client.cpp
- This is the client side code to be run to connect to the server
- demo.mp4
- This is a sample output video of the code running
-
Run the MainServer.cpp in Terminal 1 as:
$ g++ MainServer.cpp -o s
$ ./s
- This will start the server on PORT 7070
-
Run the Client.cpp in Terminal 2 as:
$ g++ Client.cpp -o c -lpthread
$ ./c 127.0.0.1
- This will connect the client to the server
- Multiple Terminals can be opened and hence multiple clients can parallely communicate with each other
-
Once the client is connected to the server:
- Enter a pseudo IP address (for simultion purpose only) in client terminal
- Parallely, a unique MAC will be generated
-
The same process can be followed for other client
-
Now, the clients can send messages in the above format and the server will handle the queries
-
The main query, that is an ARP request is processed as
- First, the client sends the ARP request for the desired IP address (assuming that the client had called a
LL
earlier) - Now, the server will receive this message
- The server will then broadcast this message to all the connected clients
- If the IP matches with any of the clients, then that client will respond back to the server with its MAC address
- Then, the server will send this MAC address to the requested client
- First, the client sends the ARP request for the desired IP address (assuming that the client had called a
Here is a sample video of the same