Question: Overview In this warmup project, you are going to implement a client and a server program that will send a command over the network. The

Overview
In this warmup project, you are going to implement a client and a server program that will send a command over the network. The command simply turns on an LED light. However, the LED light speaks a special protocol. All we know about this protocol is the packet format used for turning on the light. Your task is to create this packet and then send it to the server for turning on this light.
Server Specifications
The server takes two arguments:
$ lightserver -p -l
1.PORT - The port server listens on.
2.Log file location - Where you will keep a record of actions.
For example:
$ lightserver -p 30000-l /tmp/logfile
Deliverables (each worth 5 points)
Server must parse two command line arguments, port and log locations.
The server must not exit after receiving a single packet.
Once a client connects, it logs a message in the following format "Received connection from "
Once it receives a hello message from the client, it logs the connection and sends a hello back to the client.
You can assume the packet format is the following:
+-----------------+--------------------------+-------------------------+
||||
||||
|Version(4 bytes)|Message type (4 bytes)|Message Length (4 bytes)|
||||
||||
+-----------------+--------------------------+-------------------------+
||
||
| Message (Max 8 Bytes)|
||
||
+----------------------------------------------------------------------+
It receives the packet header first, followed by the message. Hint: You need two RECV calls.
Check if Version ==17. If not, log an error message VERSION MISMATCH and continue to listen. Do not exit.
If Version ==17, check the message type. If message Type is 1- the corresponding command is LIGHTON. If message type is 2- the corresponding command is LIGHTOFF. No other command is supported.
If the server sees a supported command, log EXECUTING SUPPORTED COMMAND: COMMANDNAME, else log <IGNORING UNKNOWN COMMAND: COMMANDNAME.
Send back a SUCCESS message to the client.
It turns on or turns off the LED on your circuit based on the command sent by the client.
Make sure server does not exit on 0 byte messages.
Client Specifications
$ lightclient -s -p -l LOGFILE
The client takes three arguments:
Server IP - The IP address of the server.
PORT - The port the server listens on.
Log file location - Where you will keep a record of packets you received.
For example:
$ lightclient -s 192.168.2.1-p 6543-l LOGFILE
Client Requirements (each worth 5 points, item 7 is worth 10 points)
The client must parse three command line arguments, server, port, and logfile.
The client should connect to the server on the specified port.
Constructs and sends a hello packet to the server.
+-----------------+--------------------------+-------------------------+
||||
||||
|Version(4 bytes)|Message type (4 bytes)|Message Length (4 bytes)|
||||
||||
+-----------------+--------------------------+-------------------------+
|

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!