Lab Assignment--Sockets


Lab Code

To get the sample and exercise code, please use the following commands in your cs330 directory:
   curl -O -s https://www.labs.cs.uregina.ca/330/Sockets/Lab9.zip
   unzip Lab9.zip
   

Goal:

Create two-way communication so that the client and server both read and write to the socket.

Details:

The client code is given for you in the main directory. It prompts the user for what command that they want to execute on the server. It sends a character over the socket and then it listens (in the form of the read) for the response from the server.

You task will be to create the server to execute the command specified by the client. You will not change the client code.

Once a connection is established, your server will:

Sample Run

Please note that your server will stay running allowing for multiple client connections (ie. you will only type ./server once; you will type ./client three times to test the three commands). Only two commands are shown below.
$ ./client

 hostname:839490fb59fd

 port number:59549
Connection established
What command would you like the server to execute?
Type a number in the round bracket
(1)date
(2)env
(3)ip addr show
1
ascii value of char 1
Executing Command and Sending on Socket
Mon Nov 15 21:20:31 UTC 2021
$ ./client

 hostname:839490fb59fd

 port number:59549
Connection established
What command would you like the server to execute?
Type a number in the round bracket
(1)date
(2)env
(3)ip addr show
3
ascii value of char 3
Executing Command and Sending on Socket
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
1966: eth0@if1967:  mtu 1500 qdisc tbf state UP group default qlen 1000
    link/ether 02:42:ac:12:00:06 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.18.0.6/16 brd 172.18.255.255 scope global eth0
       valid_lft forever preferred_lft forever

Common Errors!

Remember that on the server side you will work with "sfd" to send information over the socket.

Remember that the number is sent as a character. Hint: you might have to write something like: '1'

Deliverables (2 files):