Java Reference
In-Depth Information
label) about the planet. Save all this extra information in the database and retrieve
it when the application starts running. You'll find useful information at ht-
tp://nineplanets.org/ .
Summary
Anetworkisacollectionofinterconnectednodesthatcansharehardwareandsoftware
amongusers.Communicationbetweenhostnodesoccursviasockets,whereasocketis
anendpointinacommunicationslinkbetweentwoprocesses.Theendpointconsistsof
anIPaddressthatidentifiesahost,andaportnumberthatidentifiesaprocessrunning
on that network node.
One process writes a message to a socket, which breaks this message into a series
of packets and forwards these packets to the other process's socket, which recombines
them into the original message for that process's consumption.
TCP is used to create an ongoing conversation between two hosts by sending mes-
sages back and forth. Before this conversation can occur, a connection must be estab-
lishedbetweenthesehosts.Afterthisconnectionhasbeenestablished,TCPentersapat-
ternofsendingamessagepacketandwaitingforareplythatthepacketarrivedcorrectly
(orforatimeouttoexpirewhenthereplydoesn'tarrivebecauseofanetworkproblem).
This send/reply cycle guarantees a reliable connection.
Because it can take time to establish a connection, and because it also takes time to
sendpacketsbecauseoftheneedtoreceivereplyacknowledgments(ortimeouts),TCP
isfairlyslow.Incontrast,UDP,whichdoesn'trequireconnectionsandpacketacknow-
ledgement,ismuchfasterthanTCP.However,UDPisn'tasreliable(there'snoguaran-
teethatapacketwillarrivecorrectlyorevenarrive)asTCPbecausethere'snoacknow-
ledgment. Furthermore, UDP is limited to single-packet one-way conversations.
The java.net package provides Socket and ServerSocket classes for per-
forming TCP-based communications. It also provides DatagramSocket , Data-
gramPacket , and MulticastSocket classes for performing UDP communica-
tions.
AURLisacharacterstringthatspecifieswherearesource(e.g.,awebpage)isloc-
ated on a TCP/IP-based network (e.g., the Internet). Also, it provides the means to re-
trieve that resource.
The java.net packageprovides URL and URLConnection classesforaccessing
URL-based resources. It also provides URLEncoder and URLDecoder classes for
encodinganddecodingURLs,andthe URI classforperformingURI-basedoperations
(e.g., relativization) and returning URL instances containing the results.
Search WWH ::




Custom Search