Solved–Lab 1: Introduction to Socket Programming –Solution

$35.00 $24.00

Lab 1: Introduction to Socket Programming First, find two other groupmates. You must implement and test your programming assignments on a machine (Tux machines) on the engineering network system. Your work will be tested and graded on an engineering machine (Tux machine). I strongly advise you to read beej’s guide at : http://beej.us/guide/bgnet/ (Simple, easy-to-understand…

You’ll get a: . zip file solution

 

 

Description

5/5 – (2 votes)

Lab 1: Introduction to Socket Programming

First, find two other groupmates. You must implement and test your programming assignments on a machine (Tux machines) on the engineering network system. Your work will be tested and graded on an engineering machine (Tux machine).

I strongly advise you to read beej’s guide at :

http://beej.us/guide/bgnet/ (Simple, easy-to-understand tutorial)

FOR ALL THREE LABS IN THIS SEMESTER, you must use C or C++ for one of the programs and a different language of your choice for the second one. It is your responsibility to check that your preferred language is REMOTELY available on Tux Unix machines.

Example: if you write a client in C or C++, then you must use another language for the server.

Part A: Datagram socket programming

The objective is to design a String Processing Server (SPS). This SPS operates string operations as requested by a client. Your server must offer three operations: 1) number of consonants (cLength) in a string, 2) String Disemvoweling, 3) String Uppercasing. Strings are limited to a maximum of 252 characters. “Disemvowelling” means removing voyels (without replacing). “Uppercasingmeans changing any lower case letter into its corresponding uppercase.

  1. cLength of a string

A client will send a string S to the server, and the server will return the number of consonants in S.

The client sends a message with the following format (not to scale):

Total Message Length (TML)

Request ID

Operation

String

One byte

One byte

One byte

Variable                           

Total Message Length (TML) is an integer representing the total numbers of bytes making the message (header + string) including TML.

Request ID is an integer representing the request ID. This will allow a client to distinguish its requests.

Operation is the operation requested (5 (0x05) for cLength, 80 (0x50) for Disemvoweling, and 10 (0x0A) for Uppercasing)

String is the string parameter (252 bytes Max)

Example: suppose the Client requests for the clength of sentence “Hello”, the message will contain (if this is the 7th request):

0x08

0x07

0x05

0x48

0x65

0x6C

0x6C

0x6F

The Server will respond with a message with this format:

Total Message Length (TML)

Request ID

Answer (Length)

one byte

1 byte

1 byte

Example: Since “Hello” has three consonants, the server will respond to the 7th request (example above) with:

0x03

0x07

0x03

  1. String Disemvoweling

The Client will send a request with the following format

Total Message Length (TML)

Request ID

Operation

String

1 byte

1 byte

One byte

Variable                            

The meaning of the fields is the same as for requesting the length (see above). The only difference is that the Operation field will contain the value 0x50.

Example: suppose the Client needs to disemvowel the sentence “Hello”, the message will contain (if this is the 8th request):

0x08

0x08

0x50

0x48

0x65

0x6C

0x6C

0x6F

The server answers with a packet with this form:

Total Message Length (TML)

Request ID

String

1 byte

1 byte

variable

Example: The server will respond to the 8th request with:

0x05

0x08

0x48

0x4C

0x4C

  1. String Uppercasing

The Client will send a request with the following format

Total Message Length (TML)

Request ID

Operation

String

1 byte

1 byte

One byte

Variable                            

The meaning of the fields is the same as for requesting the length (see above). The only difference is that the Operation field will contain the value 0x0A.

Example: suppose the Client needs to uppercase the sentence “Hello”, the message will contain (if this is the 12th request):

0x08

0x0C

0x0A

0x48

0x65

0x6C

0x6C

0x6F

The server answers with a packet with this form:

Total Message Length (TML)

Request ID

String

1 byte

1 byte

variable

Example: The server will respond to the 8th request with:

0x08

0x0C

0x48

0x45

0x4C

0x4C

0x4F

    1. Repetitive Server: Write a datagram String Processor server (ServerUDP.xxx) in C or C++. This server must respond to requests as described above. The server must run on port (10010+GID) and could run on any machine on the Internet. GID is your group ID. The server must accept a command line of the form: server portnumber where portnumber is the port where the server should be working. For example, if your Group ID (GID) is 13 then your server must listen on Port # 10023.

    2. Write a datagram client (ClientUDP.yyy) This program must be written in any language (other than C or C++) you prefer, but remotely available on Tux machines. This client:

      1. Accepts as command line of the form: client servername PortNumber Operation String where servername is the server name, PortNumber is the port number, Operation is the operation requested (5 for cLength, 80 for Disemvoweling, and 10 for Uppercasing)), and String is the string.

      2. forms a message as described above

      3. Sends the message to the server and waits for a response

      4. Prints out the response of the server: the request ID and the response

      5. Prints out the round trip time (time between the transmission of the request and the reception of the response)

Part B: TCP socket programming

Repeat part A using TCP sockets to produce (ServerTCP.xxx, ClientTCP.yyy

What to turn in?

  1. Electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named lab1-name1-name2 where name1 and name2 are the last names of two teammates. Zip the folder and post it on Canvas. Submit separately (not inside the zipped folder) the report as a Microsoft or PDF file. A penalty of 10 points will be applied if these instructions are not followed.

  1. Your report must:

    1. state whether your code works

    2. Clearly explain how to compile and execute your code. If the TA needs your presence to compile and execute your code, then a 30% penalty will be applied.

    3. If needed, report/analyze (as appropriate) the results. The quality of analysis and writing is critical to your grade.

Good writing and presentation are expected.

If the TA is unable to access/compile/execute your work based on your report, a 30% penalty will be applied.

If the turn in instructions are not correctly followed, 10 pts will be deducted.

Grading:

1) 25 points per program (2 clients and 2 servers)

2) Code does not compile on Tux machine: 0% credit

3) Code compiles on Tux machines but does work: 5% credit

4) Code compiles and interacts correctly with counterpart from the same group: 60% credit

5) Code compiles and interacts correctly with counterpart from other groups: 100% credit

How to get started?”:

This is just an introduction to socket programming: I advise you to work ACTIVELY to implement these programs.

Step 1: download, compile, and execute Beej’s sample programs (UDP-client.c and UDP-server.c )

Step 2: get familiar with this code: study key socket programming calls/methods/functions

Step 3: improve the server to echo (send back) the string it receives.

Step 4: improve the client to receive the echo and to print it out.

Step 5: SAVE the improved versions (you may need to roll back to them if things turn bad)

Step 6: All you need now is “forming” your messages based on the specified format (lab 1 protocol).

For the TCP socket programming, redo Step 1-6 using Beej’s stream sample programs TCP-server.c and TCP-client.c.

Help Tools:

Besides this lab, I posted the following programs:

  1. TCP-server.c (Beej’s stream server)

  2. TCP-client.c (Beej’s stream client)

  3. UPD-server.c (Beej’s datagram server)

  4. UDP-client.c (Beej’s datagram client)

  5. TCPServerDisplay.c : this program is a modification of Beej’s TCP server: it takes as input a port number to run on and displays in hexadecimal what it receives.

  6. UDPServerDisplay.c : this program is a modification of Beej’s UDP server: it take as input a port number to run on and display in hexadecimal what it receives.

7) packedStruct.c : this program demoes how to create a “packed” struct in C.