27-08-2014, 12:07 PM
Implementation of Socket Programming and RMI Using Simulating Environment Project Report
Implementation of Socket.pdf (Size: 1.27 MB / Downloads: 68)
Abstract
A network comprises of collection of nodes and the medium which connects them. These nodes are connected to each other for
the reason of data transmission, which can be in any form i.e. messages, media, function invocation etc. The data transmission can be carried
out in two modes: Synchronous transfer and Asynchronous transfer. In this expanded world where data transmission plays a vital role for
communication in any firm, it becomes very necessary to use the network intelligently for effective transmission with less traffic overhead. This
paper deals with two such techniques which can be selected according to the need of any organization. The two techniques are Socket
Programming and Remote Method Invocation. Socket Interface is one of the fundamental technologies underlying the internet. If socket
programming is implemented at hardware level, the communication between hosts will occur much faster than it is today. Socket programming
can be implemented at both hardware and software. In this paper both Socket programming and RMI have been discussed in detail and
comparative study is done between them on different parameters.
Many papers and reviews have been published that deals with Socket programming and Remote Method Invocation (RMI). As to start off with
the survey, this paper contains the history, background and detailed description of Socket Programming and Remote method Invocation (RMI),
clearly mentioning what they are. This paper will also focuses on the comparative study of both Socket Programming and RMI , their
advantages and disadvantages, their function, how they work and different scenarios where they can be used.
INTRODUCTION
he term network programming refers to writing
programs that execute across multiple devices, in
which the devices are all connected to each other
using a network. A network is all about connecting
different machines together for purpose of sharing
devices, jobs or communication. The most exciting aspect
of Java is that it incorporates an easy to use, cross
platform model for network communication. The java.net
package of J2SE APIs contains a collection of classes and
interfaces that provide low level as well as high level
communication details, allowing you to write programs
that focus on solving the problem at hand. The java.net
package supports two common network protocols:
• TCP: TCP stands for Transmission Control
Protocol, which allows for reliable
communication between two applications. TCP
is typically over the Inernet Protocol (IP), and is
referred as TCP/IP.
• UDP: UDP stands for User Datagram Protocol, a
connectionless protocol, that allows for packets
of data to be transmitted between
HISTORY, OVERVIEW AND DETAILED DISCUSSION ON SOCKET PROGRAMING
Sockets were developed in 1981 at the University of
California, Berkeley. The project was sponsored by
ARPA (Advanced Research Pojects Agency) in 1980.
Initially, in 1983, the sockets were referred as Berkeley
Sockets and were implemented on 4.2 BSD UNIX
operating system. It was also known as Berkeley
Software Distribution socket API. The main objectivewas the transport of TCP/IP software to UNIX. In 1986,
AT&T introduced the Transport Layer Interface (TLI)
with socket like functionality, which was more network
independent. UNIX includes both TLI and Sockets after
SVR4.[3]
What Exactly Is a Socket?
The notion of a socket only allows a single computer to
serve many different clients at once, as well as serving
many different types of information. This is managed by
the introduction of a port which is a numbered socket on
a particular machine. A server process is said to “listen”
to a port until a client connects to it. A server is allowed
to accept multiple clients connected to the same port
number, although each session is unique.[4] To manage
multiple client connections, a server process must be
multithreaded or must have some other means of
multiplexing simultaneous I/O.
Sockets provide the communication mechanism between
two computers using TCP. A client program creates a
socket on its end of the communication and attempts to
connect that socket to a server. When the connection is
made, the server creates a socket object on its end of the
communication. The client and server can now
communicate by writing to and reading from the socket.
The java.net.Socket class represents a socket, and the
java.net.ServerSocket class provides a mechanism for the
server program to listen for clients and establish
connections with them.
Steps for Establishing a TCP Connection Between Two Computers Using Sockets
Step 1: The server instantiates a ServerSocket object,
denoting which port number communication is to occur
on.
Step 2: The server invokes the accept() method of the
ServerSocket class. This method waits until a client
connects to the server on the given port.
Step 3: After the server is waiting, a client instantiates a
Socket object, specifying the server name and port
number to connect to.
Step 4: The constructor of the Socket class attempts to
connect the client to the specified server and port
number. If communication is established, the client now
has a Socket object capable of communicating with the
server.
Step 5: On the server side, the accept() method returns a
reference to a new socket on the server that is connected
to the client's socket.
RMI Architecture
As shown in Fig 5, the server calls the registry to
associate (or bind) a name with a remote object. The
client looks up the remote object by its name in the
server's registry and then invokes a method on it. The
illustration also shows that the RMI system uses an
existing web server to load class definitions, from server
to client and from client to server, for objects
Mobile Behavior
RMI can move behavior
(class implementations) from client to server and
server to client. For example, you can define an
interface for examining employee expense reports to
see whether they conform to current company
policy. When an expense report is created, an object
that implements that interface can be fetched by the
client from the server. When the policies change, the
server will start returning a different
implementation of that interface that uses the new
policies. The constraints will therefore be checked on
the client side-providing faster feedback to the user
and less load on the server-without installing any
new software on user's system. This gives you
maximal flexibility, since changing policies requires
you to write only one new Java class and install it
once on the server host.
MY OBSERVATIONS ON SOCKET PROGRAMMING AND RMI
RMI enables a higher level of abstraction in
programming. It hides the details of socket server,
socket, connection, and sending or receiving data. It even
implements a multithreading server under the hood,
whereas with socket-level programming you have to
explicitly implement threads for handling multipleclients. The socket API is closely related to the operating
system, and hence has less execution overhead. For
applications which require high performance, this may
be a consideration.
RMI clients can directly invoke the server method,
whereas socket-level programming is limited to passing
values. Socket-level programming is very primitive.
As an analogy, socket-level programming is like
programming in assembly language, while RMI
programming is like programming in a high-level
language.
CONCLUSION AND FUTURE WORK
In this paper an attempt was made to investigate in to
socket programming and remote method invocation. The
advantage of Socket Programming over RMI is
discussed. Though Socket programming is best suitable
for communication between clients and server but
advent of RMI can’t be ignored. It is also equally
important but for very specific tasks. Due to the
constraint of length and scope of the paper, Socket
programming and RMI can’t be easily summarized but
an effort had been made to show the comparison
between them. There are works done on socket
programming ever since its advent. This is proved as
Windows, Macintosh and UNIX provide interoperability with socket interface. Java is taking over socket
programming however the portability can’t be matched.
Keeping all aspects on the table I believe socket
programming has yet to evolve in its types and ways it
will perform in applications. All these will require the
thought to have faster and reliable transactions between
the server and clients.