Sockets - Socket Communications in Java The Socket class is...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Socket Communications in Java The Socket class is the low-level interface to the communications line Client Server ___________________ ____________________ | | | | | ______ | | ______ | | / \ | Communications | / \ | | / Socket \<-------------------->/ Socket \ | | \ / | Line | \ / | | \______/ | | \______/ | | | | | |___________________| |____________________|
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
You can think of the Socket object as being analogous to the telephone device as far as being the Java interface to the communications line. Socket communications is 1. based on TCP\IP protocol 2. bi-directional 3. continuous connection 4. guaranteed delivery of data packets 5. guaranteed sequence of delivery of data packets Datagram Sockets are like "telegrams" There is another kind of connection provided by a class called DatagramSocket. This kind of communication sends only one packet of data rather than maintaining a continous connection. So if you only have something brief to say like "Congratulations!" or "Can you meet me for lunch?" then, like a telegram, one data packet will be plenty. Interestingly, DatagramSocket does not guarantee delivery of the packet! If an intermediate node in the network is running out of storage, for example, it will disgard data packets to avoid going down. Socket communications will automatically retransmit the packets. DatagramSockets will not. How can a network protocol do this, you ask! But. ..isn't that how the U.S. Post Office works? Hummm. ..! We put a stamp on a letter and put it in the mail box and assume it will be delivered. But if you want a guarantee of delivery, you have to us "registered mail" and pay more. If the network is "pretty reliable", not many packets are lost. And, there are applications where loss of a data packet is not catastrophic, like "stock quotes" or a game. You will shortly be sent again the price of a stock, or the location of your opponent's tank, so missing a data packet here and there is not a big deal.
Background image of page 2
The resources on the server-side application are usually dramatically less with DatagramSocket communications. We can send out thousands of packets (to different addresses) periodically with a single network connection and a single thread to do a stock quotes type of application, whereas keeping continuously connected to all subscribers would not be feasible. (This is why the internet "works", isn't it!) High-level classes DataInputStream and DataOutputStream are typically used with Socket communications In Java, we typically distribute I/O function between a low-level, device-specific class
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/25/2010 for the course ECE 309 taught by Professor Bowman during the Spring '09 term at N.C. State.

Page1 / 7

Sockets - Socket Communications in Java The Socket class is...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online