Presentation is loading. Please wait.

Presentation is loading. Please wait.

MCA – 405 Elective –I (A) Java Programming & Technology

Similar presentations


Presentation on theme: "MCA – 405 Elective –I (A) Java Programming & Technology"— Presentation transcript:

1 MCA – 405 Elective –I (A) Java Programming & Technology
By: Abhishek Khare (SVIM - INDORE M.P) MCA – 405 Elective –I (A) Java Programming & Technology © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

2 UNIT-5 Networking & RMI The term network programming refers to writing programs that execute across multiple devices (computers), in which the devices are all connected to each other using a network. The java.net package of the J2SE APIs contains a collection of classes and interfaces that provide the low-level communication details The java.net package provides support for the two common network protocols: TCP: TCP stands for Transmission Control Protocol, which allows for reliable communication between two applications. TCP is typically used over the Internet Protocol, which is referred to as TCP/IP. UDP: UDP stands for User Datagram Protocol, a connection-less protocol that allows for packets of data to be transmitted between applications. © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

3 Introduction: What Is a Socket?
Normally, a server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request. On the client-side: The client knows the hostname of the machine on which the server is running and the port number on which the server is listening.  © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

4 A socket is one endpoint (combination of an IP address and a port number) of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent. © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

5 What is client server ? “relating to a computer system in which a central server supports a number of networked workstations.” © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

6 RESERVED SOCKET Reserved port numbers.                                     Service        Port no.                        echo           7                                            daytime     13                        ftp              21                        telnet         23                        smtp          25                        finger         79                        http           80                        pop3         110  If we consider the range of the port numbers, there are 0 to 65,535 ports available. The port numbers ranging from are reserved ports or we can say that are restricted ports. All the 0 to 1023 ports are reserved for use by well-known services such as FTP, telnet and http and other system services. These ports are called well-known ports.  © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

7 Proxy servers In computer networks, a proxy server is a server (a computer system or an application) that acts as an intermediary for requests from clients seeking resources from other servers. A client connects to the proxy server, requesting some service, such as a file, connection, web page, or other resource available from a different server and the proxy server evaluates the request as a way to simplify and control its complexity. © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

8 What is an InetAddress? It is a class in Java which represents an Internet Protocol (IP) address. An instance of an InetAddress consists of an IP address and possibly corresponding hostname.  The Class represents an Internet address as Two fields: 1- Host name(The String)=Contain the name of the Host. 2- Address(an int)= The 32 bit IP address. © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

9 TCP sockets, UDP sockets
Datagram communication: The datagram communication protocol, known as UDP (user datagram protocol), is a connectionless protocol, meaning that each time you send datagrams, you also need to send the local socket descriptor and the receiving socket's address. As you can tell, additional data must be sent each time a communication is made. Stream communication: The stream communication protocol is known as TCP (transfer control protocol). Unlike UDP, TCP is a connection-oriented protocol. In order to do communication over the TCP protocol, a connection must first be established between the pair of sockets. While one of the sockets listens for a connection request (server), the other asks for a connection (client). Once two sockets have been connected, they can be used to transmit data in both (or either one of the) directions. © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

10 Java RMI Overview Java RMI or Remote Method Invocation is an example of Remote Procedure Call (RPC)enabling client program to locate the server object and remotely invoke the methods from server through server’s stub and skeleton function © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

11 The main Java RMI component consists of 3 elements: Client Server
Invoke method on remote object Server Process that owns remote object Registry Name server that relates objects with unique names From the figure above, we can see the process of Java RMI is divided into 4 steps: Instantiate server object and then register it to RMI registry service with unique name Client program locates server object from RMI registry service with associated name Once server object is found is RMI registry, RMI registry returns server stub Server stub handles the data communication with Server skeleton on server side.  © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

12 Server Object Interface Server Object Server Stub
An interface defines the methods for the server object Server Object An instance of the server object interface Server Stub An object that resides on the client host and serves as a representative of the remote server object Server Skeleton An object that resides on the server host. It communicates with the stub and the actual server object RMI Registry It is service to register remote objects and to provide naming services for locating objects Client program A program that invokes the methods in the remote server object © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

13 Example Chat communication is the process of exchanging messages between two systems continuously. Anyone can break the communication. Both systems come with the following same responsibilities. Reading from keyboard. Uses an input stream like BufferedReader connected to System.in. Sending data to the other system what is read from keyboard. Uses an output stream like PrintWriter connected to getOutputStream() method of Socket. Receiving data from the other system. Uses an input stream like BufferedReader connected to getInputStream() method of Socket. As the responsibilities are same, both client and server programs contain the same stream objects and same code. The order of using stream objects varies in the while loop. © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

14 To come out of the chat, type Ctrl+C.
Client program: GossipClient.java To come out of the chat, type Ctrl+C. Client sends first and then receives where as server first receives and then sends. © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

15 © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.

16 © 2013 Abhishek Khare JAVA Notes (SVIM) All Rights Reserved.


Download ppt "MCA – 405 Elective –I (A) Java Programming & Technology"

Similar presentations


Ads by Google