Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java Network Programming

4,658 views

Published on

Published in: Technology, News & Politics
  • Be the first to comment

Java Network Programming

  1. 1. IADCS Diploma Course Java Network Programming U Nyein Oo COO/Director(IT) Myanma Computer Co., Ltd
  2. 2. Objectives <ul><li>Introduction to Internet and its working </li></ul><ul><li>Network Protocol </li></ul><ul><li>TCP and UDP </li></ul><ul><li>Explain Client/Server computing </li></ul><ul><li>Classes of java.net package: </li></ul><ul><ul><li>InetAddress </li></ul></ul><ul><ul><li>Socket </li></ul></ul><ul><ul><li>ServerSocket </li></ul></ul><ul><ul><li>DatagramSocket </li></ul></ul><ul><ul><li>DatagramPacket </li></ul></ul>
  3. 3. Objectives(cont) <ul><li>Explain Web related classes: </li></ul><ul><ul><li>URL Class </li></ul></ul><ul><ul><li>URLConnection Class </li></ul></ul><ul><ul><li>URLEncoder Class </li></ul></ul><ul><ul><li>ContentHandler Class </li></ul></ul>
  4. 4. Networking and Internet <ul><li>Networking is the concept of connecting two machines </li></ul><ul><li>Internet is nothing but many computers communicating with each other using protocols </li></ul>
  5. 5. Protocol <ul><li>Protocols help in passing information from one computer to another </li></ul><ul><li>Computers communicate with each other by exchanging packets of data </li></ul><ul><li>Internet Protocol (IP) is the network protocol used to send information from one computer to another over the Internet </li></ul>
  6. 6. Protocol (Contd…) <ul><li>The communication of computers is possible using Ports </li></ul><ul><li>Commonly used port numbers </li></ul>Port No Protocol Description 21 FTP File Transfer Protocol 23 TELNET Remote Login 25 SMTP Simple Mail Transfer Protocol
  7. 7. TCP and UDP <ul><li>Communication takes place with the help of transport protocols </li></ul><ul><li>TCP establishes link between the source port’s IP address and destination port’s IP address </li></ul>
  8. 8. TCP and UDP (Contd…) <ul><li>UDP is a connectionless protocol as it does not establish a link for the connection </li></ul><ul><li>When UDP is used, the destination port and IP addresses are written down in a datagram and the datagram is sent to the destination </li></ul><ul><li>UDP is less reliable as compared to TCP since there is no delivery assurance </li></ul>
  9. 9. Client Server Computing <ul><li>The Net provides a variety of services; these services are organized according to the client/server architecture </li></ul><ul><li>The client programs like browsers create connections to server programs such as Web and FTP servers </li></ul>
  10. 10. Client Server Computing (Contd…) <ul><li>The client makes the request to the server and the server responds by providing the required service to the client </li></ul><ul><li>Clients communicate through client sockets and servers communicate through server sockets </li></ul>
  11. 11. Inside java.net <ul><li>The java.net package provides the classes that support socket-based client/server communication </li></ul><ul><li>Classes of java.net package: </li></ul><ul><ul><li>InetAddress </li></ul></ul><ul><ul><li>Socket </li></ul></ul><ul><ul><li>ServerSocket </li></ul></ul><ul><ul><li>DatagramSocket </li></ul></ul><ul><ul><li>DatagramPacket </li></ul></ul>
  12. 12. InetAddress Class <ul><li>This class eases finding of addresses on the Internet </li></ul><ul><li>Only the name needs to be supplied to get the respective address </li></ul><ul><li>It supports both numeric IP address and hostnames </li></ul>
  13. 13. Socket Class <ul><li>Java programs connect to the network using a socket </li></ul><ul><li>Socket helps in establishing connections and developing applications between the client and server </li></ul>
  14. 14. ServerSocket Class <ul><li>The TCP server socket is implemented using the ServerSocket class </li></ul><ul><li>The server socket is made to listen using the accept( ) method and thereby wait till an incoming connection is established </li></ul><ul><li>The address of the host to which the socket is connected is returned using getInetAddress( ) method </li></ul>
  15. 15. DatagramSocket Class <ul><li>This class is used to implement the client and server sockets using the User Datagram Protocol (UDP) </li></ul><ul><li>UDP is a connectionless protocol that enables client and server to exchange information using datagrams </li></ul><ul><li>Datagrams are nothing but chunks of data </li></ul><ul><li>The datagrams are sent and received using the send( ) and receive( ) methods respectively </li></ul>
  16. 16. DatagramPacket Class <ul><li>This class encapsulates the datagrams that are sent and received using objects of DatagramSocket class </li></ul><ul><li>There are two different constructors, one for datagrams that are received from the datagram socket and the other for creating datagrams that are sent over the datagram socket </li></ul>
  17. 17. Web related classes <ul><li>While working with the Internet and World Wide Web, we need to create and manipulate URLs </li></ul><ul><li>The java.net package also provides a set of classes that support Web-specific applications  </li></ul><ul><li>java.net web-related classes: </li></ul><ul><ul><li>URL </li></ul></ul><ul><ul><li>URLConnection </li></ul></ul><ul><ul><li>URLEncoder </li></ul></ul><ul><ul><li>ContentHandler </li></ul></ul>
  18. 18. URL Class <ul><li>URL stands for Uniform Resource Locator </li></ul><ul><li>It provides a uniform way to locate resources on the web </li></ul><ul><li>The class java.net.URL encapsulates the object on the web </li></ul>
  19. 19. URLConnection Class <ul><li>It is an abstract class </li></ul><ul><li>If we have an active HTTP connection to the web, the URLConnection class encapsulates it </li></ul><ul><li>This class supports several methods so as to modify the defaults, query and modify the current settings for a URLConnection object </li></ul><ul><li>URLConnection class is used for getting information about the web object and the connection to the web object so as to interact with the web object </li></ul><ul><li>HttpURLConnection is a subclass of the URLConnection class </li></ul>
  20. 20. URLEncoder Class <ul><li>This class is basically used for converting text strings to a suitable form useable as part of an URL </li></ul><ul><li>This class provides method called encode( ) that converts the spaces in the text to plus sign (+) </li></ul><ul><li>It uses a percent character (%) as an escape code for encoding special characters </li></ul>
  21. 21. ContentHandler Class <ul><li>ContentHandler class is used to process and extract data with MIME (Multipurpose Internet Mail Extension) types </li></ul><ul><li>MIME includes different types of objects such as sounds, images, videos, etc. </li></ul><ul><li>It provides viewers to process MIME types </li></ul>

×