Presentation is loading. Please wait.

Presentation is loading. Please wait.

SHIFT – II DEPARTMENT OF BCA SECOND YEAR ‘A’ SECTION

Similar presentations


Presentation on theme: "SHIFT – II DEPARTMENT OF BCA SECOND YEAR ‘A’ SECTION"— Presentation transcript:

1 SHIFT – II DEPARTMENT OF BCA SECOND YEAR ‘A’ SECTION
A. M. JAIN COLLEGE SHIFT – II DEPARTMENT OF BCA SECOND YEAR ‘A’ SECTION

2 Java Programming

3 “NETWORK BASICS IN JAVA”
TOPICS on “NETWORK BASICS IN JAVA” Presented by M. Ganesh Raja Assistant Professor

4 What is network? Java Networking is a concept of connecting two or more computing devices.
Internet is a network of networks. Advantage of Java Networking sharing resources centralize software management

5 Network Layers Application Level Network Layer Hardware Layer
(FTP, Telnet, etc.) Network Layer (Low-level Protocol -- IP, datagrams, etc.) Hardware Layer (Ethernet, TokenRing, X.25, etc.)

6 All the Java networking classes and interfaces use java. net package
All the Java networking classes and interfaces use java.net package. The java.net package provides the functionality for two common protocols: 1. TCP (Transmission Control Protocol) 2. UDP (User Datagram Protocol)

7 TCP-connection oriented
TCP is a connection based protocol that provides a reliable flow of data between two devices. UDP-connection less UDP protocol sends independent packets of data, called datagram from one computer to another. Transport Layer (TCP, UDP, sockets, etc.)

8 Networking is the concept of connecting multiple remote or local devices together. Java program communicates over the network at application layer. 

9 Networking Terminology
Request and Response When an input data is sent to an application via network, it is called request. The output data coming out from the application back to the client program is called response. 

10 Protocol A protocol is basically a set of rules and guidelines which provides the instructions to send request and receive response over the network.  For example: TCP, UDP, SMTP, FTP etc.

11  IP Address IP Address stands for Internet protocol address. It is an identification number that is assigned to a node of a computer in the network. For example:  Range of the IP Address   to  

12 Port Number The port number is an identification number of server software. The port number is unique for different applications. It is a 32-bit positive integer number having between ranges 0 to  

13 Java Socket Programming Socket provides an endpoint of two way communication link using TCP protocol.

14 java Socket programming is used for communication between the applications running on different JRE.
Java Socket programming can be connection-oriented or connection-less. Socket and ServerSocket classes are used for connection-oriented socket programming. DatagramSocket and DatagramPacket classes are used for connection-less socket programming. The client in socket programming support for two types. 1. IP Address of Server 2. Port number.

15 Socket Class The java. net
Socket Class The java.net.Socket class is used to create a socket so that both the client and the server can communicate with each other easily. A socket is an endpoint for communication between two computers.

16

17 Server & Client Communication

18 Output

19

20

21 InetAddress Class The Inetaddress class provides you with a limited interface to DNS for doing both forward and reverse internet address lookups An InetAddress class method corresponds to a DNS request

22 InetAddress Class No public constructor Three static methods:
InetAddress getByName(String) Static method used to retrieve the address for the host name passed as the parameter. InetAddress [ ] getAllByName(String) Static method used to retrieve all the addresses for the host name passed as a parameter. InetAddress getLocalHost( ) Static method used to retrieve the address for the current, or local, host.

23 InetAddress Class Three additional “getter” methods
String getHostName( ) Returns the host name. byte[ ] getAddress( ) Returns the IP address. String getHostAddress( ) Returns the IP address as a string.

24 DatagramPacket Class DatagramPacket(byte[] buf, int len, SocketAddress addr) Constructs a datagram packet for sending packets of length len to the specified port number on the specified host. Getter methods getAddress( ) getData( ) getLength( ) getOffset( ) getPort( ) getSocketAddress( ) Setter methods setAddress(InetAddress iaddr) setData(byte[ ] buf) setData(byte[] buf, int offset, int length) setLength(int len) setPort(int port) setSocketAddress(SocketAddress saddr)

25 URL Class URL class represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. different services use slightly different formats file://ftp.yoyodyne.com/pub/files/foobar.txt news:rec.gardening gopher://gopher.banzai.edu:1234/

26

27 output

28 URL Class - Constructors
URL(String spec) Creates a URL object from the String representation. URL(String protocol, String host, int port, String file)  Creates a URL object from the specified protocol, host, port number, and file. URL(String protocol, String host, int port, String file, URLStreamHandler handler)   Creates a URL object from the specified protocol, host, port number, file, and handler. URL(String protocol, String host, String file) Creates a URL from the specified protocol name, host name, and file name. URL(URL context, String spec) Creates a URL by parsing the given spec within a specified context URL(URL context, String spec, URLStreamHandler handler)  Creates a URL by parsing the given spec with the specified handler within a specified context.

29 URL Class - Methods Setters
set(String protocol, String host, int port, String file, String ref) set(String protocol, String host, int port, String authority, String userInfo, String path, String query, String ref) setURLStreamHandlerFactory(URLStreamHandlerFactory fac)

30 ServerSocket Used as the main connection point for some service you wish to provide. Once created, it listens for connection requests then queues the request for disposition On Unix/Linux you must be root to use

31 ServerSocket – methods
accept( ) – accepts a connection request and creates a socket to the remote user close( ) – close the server socket and wait for next connection request

32 THANK YOU


Download ppt "SHIFT – II DEPARTMENT OF BCA SECOND YEAR ‘A’ SECTION"

Similar presentations


Ads by Google