• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 40. Network Programming > The Java Socket Classes

The Java Socket Classes

Java, of course, was developed by Sun. Sun earned its reputation as a leading developer of UNIX workstations—much of the Internet runs on Sun servers. It's not surprising, therefore, that Java is designed from the ground up as a networking language. This overview shows how Java makes network programming easier by encapsulating connection functionality in socket classes:

  • Socket is the basic object in Internet communication, which supports the TCP/IP protocol. The Transmission Control Protocol/Internet Protocol (TCP/IP) is a reliable stream network connection. The Socket class provides methods for stream I/O, which make reading from and writing to Socket easy.

  • ServerSocket is an object used for Internet server programs for listening to client requests. ServerSocket does not actually perform the service; instead, it creates a Socket object on behalf of the client. The communication is performed through that object.

  • DatagramSocket is an object that uses the User Datagram Protocol (UDP). Datagram sockets are technically unreliable because no connection is involved. You send them out hoping they reach their destination, but you have no guarantee that a server is even listening. In addition, the networking software will not guarantee the delivery of UDP packages. However, communication using datagram sockets is faster because no connection is made between the sender and receiver. Think of UDP like a telegram, sent out in the hope that it will be delivered. TCP, in contrast, is more like a telephone call—you know the message is delivered because you delivered it yourself, through a connection. Streaming audio and video often use UDP.

  • SocketImpl is an abstract class that enables you to implement your own flavor of data communication. As with all abstract classes, you subclass SocketImpl and implement its methods, as opposed to instantiating SocketImpl itself.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint