1 / 32

A. M. JAIN COLLEGE

A. M. JAIN COLLEGE. SHIFT – II DEPARTMENT OF BCA SECOND YEAR ‘A’ SECTION. Java Programming. TOPICS on “ NETWORK BASICS IN JAVA ”. Presented by M. Ganesh Raja Assistant Professor. What is network? Java Networking is a concept of connecting two or more computing devices.

cgodwin
Download Presentation

A. M. JAIN COLLEGE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Java Programming

  3. 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 • (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.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. Request and ResponseWhen 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.  Networking Terminology

  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: 192.168.2.01Range of the IP Address0.0.0.0  to  255.255.255.255

  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 65535. 

  13. Java Socket ProgrammingSocket 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 Server2. Port number.

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

  16. Server & Client Communication

  17. Output

  18. 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

  19. 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.

  20. 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.

  21. 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(InetAddressiaddr) • setData(byte[ ] buf) • setData(byte[] buf, int offset, int length) • setLength(intlen) • setPort(int port) • setSocketAddress(SocketAddresssaddr)

  22. URL Class URL class represents aUniform 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 • http://www.yahoo.com/index.html • ftp://useracct@someftpserver.com • news:rec.gardening • gopher://gopher.banzai.edu:1234/

  23. output

  24. 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.

  25. 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)

  26. 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

  27. 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

  28. THANK YOU

More Related