Java Reference
In-Depth Information
}
else
else
{
throw
throw new
new
IllegalArgumentException
(
"Wanted Date, got "
+
o
);
}
}
catch
catch
(
ClassNotFoundException e
) {
System
.
err
.
println
(
"Wanted date, got INVALID CLASS ("
+
e
+
")"
);
}
catch
catch
(
IOException e
) {
System
.
err
.
println
(
e
);
}
}
}
I ask the operating system for the date and time, and then run the program, which prints the
date and time on a remote machine:
C:\javasrc\network>
date /t
Current date is Sun 01-23-2000
C:\javasrc\network>
time /t
Current time is 2:52:35.43p
C:\javasrc\network>
java network.DaytimeObject aragorn
Time on aragorn is Sun Jan 23 14:52:25 GMT 2000
C:\javasrc\network>
UDP Datagrams
Problem
You need to use a datagram connection (UDP) instead of a stream connection (TCP).
Solution
Use
DatagramSocket
and
DatagramPacket
.
Discussion
Datagram network traffic is a kindred spirit to the underlying packet-based Ethernet and IP
(Internet protocol) layers. Unlike a stream-based connection such as TCP, datagram trans-
ports like UDP transmit each “packet,” or chunk of data, as a single “entity” with no neces-