1.

Explain the difference between application data and network protocol data


Answer:


2.

Decribe the relationship between TCP and IP.


Answer:


3.

What is the function of port numbers in the Internet protocol?


Answer:


4.

What is an application protocol? Name three common application protocols used over the Internet.


Answer:


5.

Write a program that uses a socket to retrieve the correct time from a timeserver using the DAYTIME protocol.

There are many servers on the Internet that provide a time service. The National Institute of Standards and Technology http://www.bldrdoc.gov/ maintains several timeservers that allow users to synchronize a clock.

One protocol used is the Daytime protocol. The Daytime protocol is a simple protocol. The user connects on port 13 and sends a newline character. The server responds by sending back an ASCII string and then disconnects. The time string from the NIST servers is in the following format:

JJJJJ YR-MO-DA HH:MM:SS TT L H msADV UTC(NIST) *

In this simple exercise, we are concerned only with the first half of the string.

   JJJJJ represents the last five digits of the Julian data. You can ignore this value.
   YR-MO-DA YR represents the last two digits of the year, MO represents the month and DA, the current day.
   HH:MM:SS is the time in hours (HH), minutes (MM) and seconds (SS). This is sent in Coordinated Universal time. You need to add an offset to    correct the time to your time zone.

Write a program that connects to three of the NIST servers listed below, using the Daytime protocol. Parse the return string and create a Date() object set to the return string's time. Print out the return string and your Date() object. Use a SimpleDateFormat to format your date. Make sure you adjust the time to your correct time zone. Use verbose output while you are connecting to the server.

NIST Timeservers

Name

Location

time-a.nist.gov

NIST, Gaithersburg, Maryland

time-b.nist.gov

NIST, Gaithersburg, Maryland

time-a.timefreq.bldrdoc.gov

NIST, Boulder, Colorado

time-b.timefreq.bldrdoc.gov

NIST, Boulder, Colorado

time-c.timefreq.bldrdoc.gov

NIST, Boulder, Colorado

utcnist.colorado.edu

University of Colorado, Boulder

time.nist.gov

NCAR, Boulder, Colorado

time-nw.nist.gov

Microsoft, Redmond, Washington

nist1.datum.com

Datum, San Jose, California

nist1.dc.glassey.com

Abovenet, Virginia

nist1.ny.glassey.com

Abovenet, New York City

nist1.sj.glassey.com

Abovenet, San Jose, California

nist1.aol-ca.truetime.com

TrueTime, AOL facility, Sunnyvale, California

nist1.aol-va.truetime.com

TrueTime, AOL facility, Virginia



Answer:


6.

Write a program that uses a socket to retrieve the correct time from a timeserver using the TIME protocol.

There are many servers on the Internet that provide a time service. The National Institute of Standards and Technology http://www.bldrdoc.gov/ maintains several timeservers that allow users to synchronize a clock.

One protocol used is the Time protocol. To use the Time protocol, a user connects on port 37 and sends a newline character. The server responds by returning a 32-bit unformatted binary number that represents the time in UTC seconds since January 1, 1900.

Write a program that connects to three of the NIST servers listed below, using the Time protocol. Convert the return value and create a Date() object set to the return string's time. Print out the return number and your Date() object. Use a SimpleDateFormat to format your date. Make sure you adjust the time to your correct time zone. Use verbose output while you are connecting to the server.

Hints:

Unlike the C language, Java does not have an unsigned data type to represent an unsigned 32-bit binary number. An int in Java represents a 32-bit    signed binary number. Usually a larger type, in this case a long, is used to store an unsigned int. Unfortunately, the DataInputStream you    need to use has only has a readUnsignedByte() method. A little clever programming and bit shifting must be used to convert the four bytes    to a long that represented the 32-bit unsigned number.


Java stores dates as the number of milliseconds since January 1, 1970. The Time protocol returns the number of seconds since January 1, 1900. To compute the difference, create a Date object set to 01/01/1970 and a Date object set to 01/01/1900. Call getTime() on each date to retrieve the milliseconds. Then subtract to find the difference. Convert the difference to seconds and add it to the return value. Convert the corrected return value to milliseconds to create your Date object.

NIST Timeservers

Name

Location

time-a.nist.gov

NIST, Gaithersburg, Maryland

time-b.nist.gov

NIST, Gaithersburg, Maryland

time-a.timefreq.bldrdoc.gov

NIST, Boulder, Colorado

time-b.timefreq.bldrdoc.gov

NIST, Boulder, Colorado

time-c.timefreq.bldrdoc.gov

NIST, Boulder, Colorado

utcnist.colorado.edu

University of Colorado, Boulder

time.nist.gov

NCAR, Boulder, Colorado

time-nw.nist.gov

Microsoft, Redmond, Washington

nist1.datum.com

Datum, San Jose, California

nist1.dc.glassey.com

Abovenet, Virginia

nist1.ny.glassey.com

Abovenet, New York City

nist1.sj.glassey.com

Abovenet, San Jose, California

nist1.aol-ca.truetime.com

TrueTime, AOL facility, Sunnyvale, California

nist1.aol-va.truetime.com

TrueTime, AOL facility, Virginia



Answer:


7.

When sending data through sockets, why is the PrintWriter class used?


Answer:


8.

Create a server application that uses the following protocol:

Client Request

Server Response

Meaning

HELLO

greeting

Sends a greeting

ECHO n

n

Echoes n back to the client

COUNT

The number of ECHO requests

Returns a count of the number of ECHO requests by client

QUIT

goodbye

Prints a goodbye and quits the connection


You may choose the greeting and goodbye messages to send.


Answer:


9.

Create a server application that will play a simple text-based game of tic-tac-toe with a client.

Design and implement a protocol to play tic-tac-toe. The server does not have to play well, just be able to choose a move and determine when a game is over. The server should be able to start a new game, accept moves from a user, make its own moves and indicate when a game is over, and who won. To implement the game, you may simply number the rows and columns and communicate moves with the row and column numbers.


Answer:


10.

Create a server application that accepts simultaneous connections from multiple clients using the following protocol:

Client Request

Server Response

Meaning

HELLO

greeting

Sends a greeting

ECHO n

n

Echoes n back to the client

COUNT

The number of ECHO requests

Returns a count of the number of ECHO requests by client

QUIT

goodbye

Prints a goodbye and quits the connection


You may choose the greeting and goodbye messages to send.

When the server socket accepts a connection, it should construct a new thread to communicate with that client.


Answer:


11.

Write a command line program to accept a URL and display the response code, content type, and content length for the URL.


Answer:


12.

Write a program to find the current sunrise and sunset times for a given date and location in the United States.

Write a graphical based program to prompt a user for a date and location. Using a URLConnection, connect to the United States Naval Observatory to access the sunrise and sunset information. The information can be obtained from a script at http://mach.usno.navy.mil/cgi-bin/aa_pap.pl. The field names are:

xxy

A four digit year.

xxm

A two digit number representing a month (01-12)

xxd

A two digit number representing the day of the month (01-31)

st

A two letter state abbreviation (following the standard post office abbreviations, such as AK, OH, NY, UT)

place

A city name


All field values are in text format.
Strip the HTML tags from the output and display it in a text area.


Answer:


13.

Write a command-line program to access an online inflation calculator to compute inflation values based on the Consumer Price Index (CPI).
The US Department of Labor maintains a CPI inflation calculator at http://146.142.4.24/cgi-bin/cpicalc.pl. The script fields names are:

cost1

A dollar amount

year1

A four digit year from 1913-2002

cost2

The computed value

year2

A four digit year from 1913-2002


The calculator computes based on:

   $ cost1 in year1 has the same buying power as $ cost2 in year2.

For example,

   $ 10000.00 in 1970 has the same buying power as $ 46340.21 in 2002.

Have a user enter cost1, year1, and year2 at the command line. Use a URLConnection to access the online calculator and return the value of cost2.
The field values are in text format. Do not include the dollar sign when sending a request.


Answer:


14.

Write your own program that obtains form data using a URLConnection.

Choose a web site that submits data using forms. Write your own program using a URLConnection to submit form data and display the results.

The name of the script executed is often found in the <FORM> tag in the action field:

<FORM name="runme" action="http:/www.runme.com/cgi-bin/run.pl" method="POST" >

To find field names look for the name field in <INPUT> or <SELECT> tags:

<INPUT type="Text" name="date" >


Answer: