Lab 8 – Sockets Solution

$30.00

Description

Introduction

Lab 8 introduces you to network communications in Perl. Your simple Perl script will contact a given server on a given port number (using protocol TCP), read the first line sent by the server and display it on the terminal.

Requirements

Your Perl script shall be named socket.pl and be marked executable.

`Usage: ./socket.pl HOSTNAME SOCKETNUMBER`

Example

./socket.pl icarus.cs.weber.edu 22

Issue an appropriate message to STDERR and exit with a non-zero return code if it fails to connect to the provided socket at the provided host.

Issue a usage message to STDERR and exit(1) if the socket parameters are not provided.

HOSTNAME can be a name such as www.google.com or an IP address such as 137.65.1.1

Test your script on icarus with ./socket.pl localhost 25 which should print something like

  1. icarus.users.weber.edu ESMTP Postfix (Ubuntu) . Print just one line and exit(0) . Your script must not hang or run more than a few seconds unless it times out

attempting to connect to an unknown host or an invalid socket number.

It is acceptable to use die() , but warning: your return codes will be unpredictable.

Helpful Hints

Refer to the simple client in perlipc.pdf (located in the Reference folder) as a guide. Use the socket() call to create a connection to the requested port on the server Read just one line and exit. If you loop (as in the simple client) your script may hang. Use print to output the received line to STDOUT

$ARGV[] contains the commandline arguments. $ARGV[0] is the first argument (hostname), etc. $#ARGV is the index of the last item in $ARGV

Clone your private repo on github.com

In the assignment module in Canvas, find the link to the Canvas page entitled “Clone your Lab 8 Repo”, click on it and follow the instructions.

Copy your private repo down to icarus

BASH

git clone https://github.com/cowancs3030spring19/lab8-YOURGITHUBUSERNAME

cd lab8-YOURGITHUBUSERNAME

Write and test socket.pl

Fire up your favorite text editor, and begin with your header:

#!/usr/bin/perl

TEXT

  • (Your name)

  • Lab 8 – Sockets

  • CS 3030 – Scripting Languages

(Add your amazing, perfect code here)

Run cucumber to check your progress

./cucumber -s

Submit your assignment code for grading

  • Remember, you must push your script in your private repo to github.com to receive any points, for all assignments in this course.

BASH

git add socket.pl

git commit -m“COMMIT MESSAGE”

git push origin master

Files created for this lab

socket.pl

Grading

Here is how you earn points for this assignment:

Cowan 03-21-2019 07:39 PM 2

FEATURES

POINTS

Must-Have Features

Script is named correctly and found in its proper place in your private repo

5

Script is executable

5

Required Features

Script prints a “Usage:” statement and exits rc=1 if there are not exactly two

5

commandline parameters

Script exits rc=0 on successful completion

5

Script writes error messages only to STDERR

10

Script prints one line from localhost

20

Script reads from a port from a named host (e.g. weber.edu)

30

Script reads from a port from an external host (not localhost)

30

Script return error message and rc!=0 on invalid hostname

20

Script return error message and rc!=0 on invalid port

20

Grand Total

150

Cowan 03-21-2019 07:39 PM

3


error: Content is protected !!