| CS 455/555 - Intro to Networks and Communication
Spring 2011: Tues/Thurs 9:30-10:45am, Spong 108 |
|
Staff
|
Program 2: Ping with TCP and UDPAssigned: Tuesday, February 15, 2011 DescriptionThe goal of this assignment is to help you become familiar with socket programming in Java using both TCP and UDP sockets. We'll be implementing a Because we're limited to running the programs on-campus where there will be little delay and very little loss, the server will add some artificial delay and ignore some ping requests (for UDP) to simulate packet loss. PingClient
PING seqno timestamp
where PING is the word "PING", seqno is the ping sequence number (between 0-9), and timestamp is the time (in milliseconds) that the message was created and sent
---- PING Statistics ----
10 packets transmitted, 7 packets received, 30% packet loss
round-trip (ms) min/avg/max = 63/190.29/290
Print the average RTT with up to 2 digits after the decimal (see Java's DecimalFormat class).
PingServer
The server's action will either be " not sent" if the ping was ignored or "delayed x ms" .
For TCP, the server will close the client connection after each ping reply is sent.
Rules
TestingA large part of your program's grade will be determined by how well it handles a set of inputs. You should test your program rigorously before submitting. Because your programs will be run and tested using a script, you must format your output exactly as I have described or you will lose points. Example 1 java PingClient
Usage: java PingClient hostname port protocol
protocol - {TCP, UDP}
java PingServer
Usage: java PingServer port protocol [seed]
protocol - {TCP, UDP}
Example 2 java PingClient vega three TCP ERR - arg 2 java PingServer 10002 tcp ERR - arg 2 Example 3 vega> java PingServer 10002 TCP 123 128.82.4.170:62628> PING 0 1297357012973 ACTION: delayed 216 ms 128.82.4.170:62629> PING 1 1297357013192 ACTION: delayed 297 ms 128.82.4.170:62630> PING 2 1297357013496 ACTION: delayed 75 ms 128.82.4.170:62631> PING 3 1297357013576 ACTION: delayed 182 ms 128.82.4.170:62632> PING 4 1297357013760 ACTION: delayed 241 ms 128.82.4.170:62633> PING 5 1297357014002 ACTION: delayed 262 ms 128.82.4.170:62634> PING 6 1297357014265 ACTION: delayed 214 ms 128.82.4.170:62635> PING 7 1297357014481 ACTION: delayed 21 ms 128.82.4.170:62636> PING 8 1297357014502 ACTION: delayed 238 ms 128.82.4.170:62637> PING 9 1297357014742 ACTION: delayed 173 ms procyon> java PingClient vega 10002 TCP PING 0 1297357012973 RTT: 218 ms PING 1 1297357013192 RTT: 298 ms PING 2 1297357013496 RTT: 75 ms PING 3 1297357013576 RTT: 183 ms PING 4 1297357013760 RTT: 241 ms PING 5 1297357014002 RTT: 263 ms PING 6 1297357014265 RTT: 215 ms PING 7 1297357014481 RTT: 21 ms PING 8 1297357014502 RTT: 239 ms PING 9 1297357014742 RTT: 173 ms ---- PING Statistics ---- 10 packets transmitted, 10 packets received, 0% packet loss round-trip (ms) min/avg/max = 21/192.6/298 Note: The delays the server uses should be the same with the same seed, but the timestamps in the client's ping message will not since they depend on the time the program was run. Also, with TCP since you are creating a new connection for each PING sent, the client's port number will be different each time. Also, the RTTs that the client reports should be similar to the example, but may not be exact. Example 3 vega> java PingServer 10002 UDP 123 128.82.4.170:47475> PING 0 1297357083680 ACTION: delayed 297 ms 128.82.4.170:47475> PING 1 1297357083979 ACTION: delayed 182 ms 128.82.4.170:47475> PING 2 1297357084161 ACTION: delayed 262 ms 128.82.4.170:47475> PING 3 1297357084423 ACTION: delayed 21 ms 128.82.4.170:47475> PING 4 1297357084445 ACTION: delayed 173 ms 128.82.4.170:47475> PING 5 1297357084618 ACTION: delayed 44 ms 128.82.4.170:47475> PING 6 1297357084662 ACTION: delayed 19 ms 128.82.4.170:47475> PING 7 1297357084681 ACTION: not sent 128.82.4.170:47475> PING 8 1297357085682 ACTION: not sent 128.82.4.170:47475> PING 9 1297357086682 ACTION: delayed 262 ms procyon> java PingClient vega 10002 UDP PING 0 1297357083680 RTT: 299 ms PING 1 1297357083979 RTT: 182 ms PING 2 1297357084161 RTT: 262 ms PING 3 1297357084423 RTT: 22 ms PING 4 1297357084445 RTT: 173 ms PING 5 1297357084618 RTT: 44 ms PING 6 1297357084662 RTT: 19 ms PING 7 1297357084681 RTT: * PING 8 1297357085682 RTT: * PING 9 1297357086682 RTT: 263 ms ---- PING Statistics ---- 10 packets transmitted, 8 packets received, 20% packet loss round-trip (ms) min/avg/max = 19/158/299 Notes/FAQs
No. You must use an actual machine name (antares, vega, capella, or procyon).
See System.currentTimeMillis()
See the setSoTimeout() function in the DatagramSocket class in the Java Class Reference (the link is under 'Useful Links' on the course webpage).
See the DecimalFormat class in the Java Class Reference.
SubmissionYou must name your source files PingClient.java and PingServer.java (note the capitalization). Make sure that you submit all files necessary to compile your program. But, do not submit compiled files (.class files). Directions for submitting your assignment through Blackboard |