Presentation is loading. Please wait.

Presentation is loading. Please wait.

Network Programming Introduction

Similar presentations


Presentation on theme: "Network Programming Introduction"— Presentation transcript:

1 Network Programming Introduction
Based on Classes in the java.net package 9/13/2018 V.B.Sanghavi

2 JAVA Networking API series of layered abstractions
basic networking capabilities are split between the java.net and the java.io defining custom protocols, using existing protocols, or building a higher-level API on top of the basic services 9/13/2018 V.B.Sanghavi

3 Low Level API Addresses, which are networking identifiers, like IP addresses. Sockets, which are basic bidirectional data communication mechanisms. Interfaces, which describe network interfaces. 9/13/2018 V.B.Sanghavi

4 High Level API URIs, which represent Universal Resource Identifiers.
URLs, which represent Universal Resource Locators. Connections, which represents connections to the resource pointed to by URLs. 9/13/2018 V.B.Sanghavi

5 Network Terminology IP Address
Connection-oriented (TCP) and connectionless protocol (UDP) Protocol Socket –allows a single comp. to serve diff.clients at once. Port Number –numbered socket Domain Naming Service(DNS) 9/13/2018 V.B.Sanghavi

6 Client-server Architecture
9/13/2018 V.B.Sanghavi

7 Networking Classes InetAddress Socket ServerSocket URL URLConnection
DatagramSocket DatagramPacket 9/13/2018 V.B.Sanghavi

8 InetAddress Encapsulates the Numerical IP address and domain name for that address. Interact with this class by hostname as it is more convenient. Can handle IPv4 and IPv6 addresses. 9/13/2018 V.B.Sanghavi

9 Factory Methods static InetAddress getLocalHost() throws UnknownHostException static InetAddress getByName(String hostname) throws UnknownHostException Static InetAddress[] getAllByName() throws UnknownHostException 9/13/2018 V.B.Sanghavi

10 static InetAddress getByAddress() throws UnknownHostException
9/13/2018 V.B.Sanghavi

11 Instance Methods Boolean equals(Object o) Byte[] getAddress()
String getHostAddress() String getHostName() Boolean isMulticastAddress() String toString() 9/13/2018 V.B.Sanghavi

12 Socket Programming for communication between the machines.
The client in socket programming must know two information: IP address Port number 9/13/2018 V.B.Sanghavi

13 Socket class endpoint for communications between the machines.
create a socket to connect to a server sockets and initiate protocol exchange. Constructor Socket (String host, int port) Socket ( InetAddress ip, int port) program 9/13/2018 V.B.Sanghavi

14 - inetAddress getInetAddress() int getPort() int getLocalPort()
Methods : - inetAddress getInetAddress() int getPort() int getLocalPort() 9/13/2018 V.B.Sanghavi

15 - public InputStream getInputStream()
Socket class Methods: - public InputStream getInputStream() - public OutputStream getOutputStream() - void close() 9/13/2018 V.B.Sanghavi

16 ServerSocket class to create a server socket that listen for local or remote client program. Constructor: ServerSocket (int port) ServerSocket (int port, int maxqueue) ServerSocket ( int port, int maxqueue, InetAddress i) program 9/13/2018 V.B.Sanghavi

17 - public Socket accept() - public InputStream getInputStream()
Methods: - public Socket accept() - public InputStream getInputStream() - public OutputStream getOutputStream() - void close() 9/13/2018 V.B.Sanghavi

18 URL class represents a URL (Uniform Resource Locator) to uniquely identify or address info. On the internet. URLs can point to files, Web sites, ftp sites, newsgroups, addresses, and other resources. 9/13/2018 V.B.Sanghavi

19 Format of URL http://www.javatpoint.com : 8080/abc / index.jsp
telnet://localhost:8000/ 9/13/2018 V.B.Sanghavi

20 URL constructors URL (String urlspecifier)
URL ( String protocol, String host, int port, String path) Exception : MalformedURLException 9/13/2018 V.B.Sanghavi

21 Methods of URL class public String getProtocol()
public String getHost() public String getPort() public String getFile() Public String toExternalForm() Program 9/13/2018 V.B.Sanghavi

22 URLConnection represents a communication link between the URL and the application. can be used to read and write data to the specified resource reffered by the URL. 9/13/2018 V.B.Sanghavi

23 Creating a URLConnection
URL url = new URL ( some_url ); URLConnection connection = url.openConnection(); 9/13/2018 V.B.Sanghavi

24 public String getContentType() public long getExpiration()
public long getDate() public String getContentType() public long getExpiration() public long getLastModified() public int getContentLength() public InputStream getInputStream() public OutputStream getOutputStream() 9/13/2018 V.B.Sanghavi

25 Program for URLConnection class to read the content of specified resource
9/13/2018 V.B.Sanghavi

26 Datagrams Bundles of information passed between machines.
When released- no assurance regarding arrival. When received- no assurance regarding data reliability. 9/13/2018 V.B.Sanghavi

27 DatagramSocket class represents a connection-less socket for sending and receiving datagram packets Constructors DatagramSocket() //Sending DatagramSocket(int port) //receiving DatagramSocket(int port, InetAddress address) 9/13/2018 V.B.Sanghavi

28 DatagramPacket class The DatagramPacket is message that can be sent or received 9/13/2018 V.B.Sanghavi

29 Constructors DatagramPacket(byte[] data, int length)
(While receiving the data) DatagramPacket(byte[] data, int length, InetAddress address, int port) (while sending the data) 9/13/2018 V.B.Sanghavi

30 Methods: InetAddress getAddress() Int getPort() byte[] getData()
Int getLength() 9/13/2018 V.B.Sanghavi

31 Content Handler and Protocol Handler
Handling a protocol taking care of the interaction between a client and a server generating requests in the correct format acknowledging that the data has been received 9/13/2018 V.B.Sanghavi

32 Handling the content converting the raw data into a format Java understands 9/13/2018 V.B.Sanghavi

33 ContentHandler implemented as subclasses of the ContentHandler
getContent() associated with a specific MIME type through the use of the ContentHandlerFactory interface createContentHandler() 9/13/2018 V.B.Sanghavi

34 ProtocolHandler implemented as subclasses of the URLStreamHandler class openConnection() toExternalForm() to implement a custom protocol needed to access Web objects identified by URLs 9/13/2018 V.B.Sanghavi

35 createURLStreamHandler()
associated with a specific protocol through the use of the URLStreamHandlerFactory createURLStreamHandler() 9/13/2018 V.B.Sanghavi


Download ppt "Network Programming Introduction"

Similar presentations


Ads by Google