Professional Documents
Culture Documents
SYSTEMS
INDEX
Sr. No. Title Date Sign
PRACTICAL 1
IMPLEMENTING CLIENT-SERVER COMMUNICATION
MODEL
TCP (Transmission Control Protocol) is a standard that defines how to establish and maintain
a network conversation via which application programs can exchange data. It defines the
basic rules defining the internet. TCP is a connection-oriented protocol, which means a
connection is established and maintained until the application programs at each end have
finished exchanging messages. It determines how to break application data into packets that
networks can deliver, sends packets to and accepts packets from the network layer, manages
flow control, and - because it is meant to provide error-free data transmission - handles
retransmission of dropped or garbled packets as well as acknowledgement of all packets that
arrive. In the Open Systems Interconnection (OSI) communication model, TCP covers parts
of Layer 4, the Transport Layer, and parts of Layer 5, the Session Layer.
Working of the programs:
• First compile and run the server file followed by the client.
• The prompt on the server shows whether it is ready and also if the client is connected
or not.
• On the client prompt the user can type the message he/she wants and press enter to
send the message.
• The server receives the message and can now reply to the client.
• This goes on until client wants to exit, which is done by him/her by typing ‘EXIT’ and
hitting the enter key.
TCP (Transmission Control Protocol) is a standard that defines how to establish and maintain
a network conversation via which application programs can exchange data. It defines the
basic rules defining the internet. TCP is a connection-oriented protocol, which means a
connection is established and maintained until the application programs at each end have
finished exchanging messages. It determines how to break application data into packets that
networks can deliver, sends packets to and accepts packets from the network layer, manages
flow control, and - because it is meant to provide error-free data transmission - handles
retransmission of dropped or garbled packets as well as acknowledgement of all packets that
arrive. In the Open Systems Interconnection (OSI) communication model, TCP covers parts
of Layer 4, the Transport Layer, and parts of Layer 5, the Session Layer.
Working of the programs:
• First compile and run the server file followed by the client.
• The prompt on server shows whether the server is ready or not.
• On the client prompt, enter the number which you want to identify, as if it is a prime
number or not.
• Server processes the number and returns the output to the client, which is displayed on
the client prompt.
import java.rmi.*;
public interface Cal_Main extends Remote
{ public int sum(int a,int b) throws RemoteException;
public int sub(int a,int b) throws RemoteException; public
int mul(int a,int b) throws RemoteException; }
import java.rmi.*;
import java.io.*; public
class Cal_Client
{ public static void main(String arg[])
{ try
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
Cal_Main p = (Cal_Main)Naming.lookup("Cal_Main");
System.out.println("Enter First Number");
String strFirst = br.readLine();
System.out.println("Enter Second Number");
String strSecond = br.readLine();
System.out.println("Sum:"+p.sum(Integer.parseInt(strFirst),Integer.par
seInt(strSecond)));
System.out.println("Sub:"+p.sub(Integer.parseInt(strFirst),Integer.pars
eInt(strSecond)));
System.out.println("Mul:"+p.mul(Integer.parseInt(strFirst),Integer.pars
eInt(strSecond)));
}
catch(Exception e)
{
System.out.println("Error Occured : "+e.getMessage());
}
}
}
Output: Server Prompt
PRACTICAL 3
IMPLEMENTATION OF RPC
Remote Procedure Call (RPC) is a protocol that one program can use to request a service
from a program located in another computer on a network without having to understand the
network's details. A procedure call is also sometimes known as a function call or a subroutine
call. RPC uses the client-server model. The requesting program is a client and the service
providing program is the server. Like a regular or local procedure call, an RPC is a
synchronous operation requiring the requesting program to be suspended until the results of
the remote procedure are returned. However, the use of lightweight processes or threads that
share the same address space allows multiple RPCs to be performed concurrently.
Working of the programs:
• Compile the client and server programs.
• First run the server program followed by the client.
• On the client prompt enter the number for the count of numbers Fibonacci Series will
be made. On the server prompt the Fibonacci Series of the required count is displayed.
I. Choosing a Container:
Choose File ->New Project ->Java Web -> Web Application -> Project Name:
CalculatorWSApplication->Next->Finish
Right-click CalculatorWSApplication node -> New -> Web Service -> Name: CalculatorWS
> Package: org.me.calculator -> Select Implement Web Service as a Stateless Session Bean -
> Finish
Click on Design View -> Click Add Operation -> Name: add -> Return Type: int -> Click
Add -> Create parameter of type int named I -> Again click Add -> Create parameter of type
int named j -> Click OK -> Click Source and code the following:
public int add(@WebParam(name = “i”) int i, @WebParam(name = “j”)int j)
{
int k = i+j;
return k;
}
Right-click the Project -> Deploy -> Expand Web Services node of CalculatorWSApplication
project -> Right-click CalculatorWS node -> Test Web Service -> Tester Page is opened in
browser -> Type any two numbers below:
Output:
File -> New Project -> Java -> Java Application -> Name: CalculatorWS_Client_Application
-> Finish->Right-click CalculatorWS_Client_Application node -> New -> Web Service
Client -> In Project, Browse to CalculatorWS web service in the CalculatorWSApplication ->
OK -> Finish -> Go to Source -> Drag the add node from the Web Services References node
below the main method -> Code the following in main() method:
public static voide main(String[] args)
{
try {
int i = 13; int j
= 29; int result =
add(i,j);
System.out.println(“Result = ” +result);
}
catch(Exception e) {
System.out.println(“Exception = ” +e); }
}
Output:
B. Using MySQL database
I. Choosing Container:
File -> New Project -> Java Web -> Web Application -> Next -> Name: BookWS -> Select
Use Dedicated Folder for Storing Libraries -> Name: BookWS -> Package: webservice ->
Select option Implement Web Service as a Stateless Session Bean -> Finish
Click Design View -> Click Add Operation -> Name: getBookDetails -> Return Type:
java.lang.String -> Click Add -> Create a parameter of type String named isbn -> OK ->
Click Source -> Modify the code spec:
@WebMethod(operationName = "getBookDetails") public String
getBookDetails(@WebParam(name = "isbn") String isbn) { //TODO
write your implementation code here:
Connection dbcon = null;
Statement stmt = null;
ResultSet rs = null;
String query = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
dbcon =
DriverManager.getConnection("jdbc:mysql://localhost/bookshop","root","123456");
stmt = dbcon.createStatement();
query = "select * from books where isbn = '" +isbn+ "'";
rs = stmt.executeQuery(query); rs.next();
String bookDetails = "<h1>The name of the book is <b>" +rs.getString("bookname")
+ "</b> and its cost is <b>" +rs.getString("bookprice") + "</b></h1>.";
return bookDetails;
}
catch(Exception e) {
System.out.println("Sorry failed to connect to the database... " +e.getMessage());
}
return null;
}
• Adding MySQL Connector
Right-click Libraries -> Select Add JAR/Folder -> Select the connector and open it
Right-click BookWS Project -> Deploy -> Expand the Web Services Directory -> Right-click
BookWS Web Service -> Test We Service -> In the browser, enter the ISBN number -> Click
getBookDetails -> We get the following:
File -> New Project -> Java Web -> Web Application -> Next -> Name:
BookWSServletClient -> Select option Use Dedicated folder for Storing Libraries -> Next ->
Finish
Right-click BookWSServletClient Project -> New -> Web Service Client -> Click Browse ->
Browse throught the Web Service which needs to be consumed -> Click ok -> Finish
• Creating a servlet
New -> Servlet -> Name: retreiveBookDetails -> Package:servlet -> Next -> Configure
Servlet Deployment to be kept defaults -> Finish -> Replace the following code spec:
out.println(“<h1>Servlet retreiveBookDetails at” +request.getContextPath()+ “</h1>”); With
the code spec of getBookDetails() operation of the web service by dragging and dropping the
getBookDetails operation. -> Now change the following code spec: Add this code –
outprintln(getBookDetails(request.getParameter(“isbn”))); to processRequest() method
between out.println(“<body”); and out.println(“</body>”)
Output:
PRACTICAL 5
IMPLEMENTATION OF A MUTUAL EXCLUSION ALGORITHM
– RING BASED ALGORITHM
One of the simplest ways to arrange mutual exclusion between the N processes without
requiring an additional process is to arrange them in a logical ring. This requires only that
each process pi has a communication channel to the next process in the ring, p(i + 1)mod N.
The idea is that exclusion is conferred by obtaining a token in the form of a message passed
from process to process in a single direction – clockwise, say – around the ring. The ring
topology may be unrelated to the physical interconnections between the underlying
computers. If a process does not require to enter the critical section when it receives the
token, then it immediately forwards the token to its neighbour. A process that requires the
token waits until it receives it, but retains it. To exit the critical section, the process sends the
token on to its neighbour.
Working of the programs:
• First compile all programs.
• Run the server first followed by the clients.
• Client 1 gets a prompt on whether he wants to use the token to send any data or not. If
yes then he can type and send the data, else no the client 2 gets a prompt for the same.
In this similar fashion, the ring based mutual exclusion algorithm works using a token.
PRACTICAL 6
IMPLEMENTATION OF AN ELECTION ALGORITHM – BULLY
ALGORITHM
The bully algorithm [Garcia-Molina 1982] allows processes to crash during an election,
although it assumes that message delivery between processes is reliable. Unlike the ring-
based algorithm, this algorithm assumes that the system is synchronous: it uses timeouts to
detect a process failure. Another difference is that the ring-based algorithm assumed that
processes have minimal a priori knowledge of one another: each knows only how to
communicate with its neighbour, and none knows the identifiers of the other processes. The
bully algorithm, on the other hand, assumes that each process knows which processes have
higher identifiers, and that it can communicate with all such processes. There are three types
of message in this algorithm: an election message is sent to announce an election; an answer
message is sent in response to an election message and a coordinator message is sent to
announce the identity of the elected process – the new ‘coordinator’. A process begins an
election when it notices, through timeouts, that the coordinator has failed. Several processes
may discover this concurrently.
Working of the program:
• After compiling and running the program, enter the number of processes.
• Give each process a Status and Priority.
• Select the initiation process.
• Final Co-coordinator with the highest priority is selected.
Program:
Output:
PRACTICAL 7
IMPLEMENTATION OF TWO PHASE COMMIT PROTOCOL
In the first phase of the two-phase commit protocol the coordinator asks all the participants if
they are prepared to commit; in the second, it tells them to commit (or abort) the transaction.
If a participant can commit its part of a transaction, it will agree as soon as it has recorded the
changes it has made (to the objects) and its status in permanent storage and is therefore
prepared to commit. It consists of a voting and a completion phase.
Working of Programs:
• Compile and run the server first followed by the client.
• Run 2/3 Clients and after server is ready Commit or Abort the clients on the
individual prompts.
• Each client is informed of a new addition and the server keeps the count of clients.
try
{ clientSocket = serverSocket.accept();
clientThread th=new clientThread(ser,clientSocket);
(ser.t).add(th);
System.out.println("\nNow Total clients are : "+(ser.t).size());
(ser.data).add("NOT_SENT");
th.start();
}
catch (IOException e)
{
}
} try
{ serverSocket.close();
}
catch(Exception e1)
{
}
}
}
class clientThread extends Thread {
DataInputStream is = null;
String line;
String destClient="";
String name;
PrintStream os = null;
Socket clientSocket = null;
String clientIdentity;
Server ser;
public clientThread(Server ser,Socket clientSocket)
{ this.clientSocket=clientSocket;
this.ser=ser;
}
public void run()
{
try
{
is = new
DataInputStream(clientSocket.getInputStream()); os =
new PrintStream(clientSocket.getOutputStream());
os.println("Enter your name."); name = is.readLine();
clientIdentity=name;
os.println("Welcome "+name+" to this 2 Phase Application.\nYou will receive
a vote Request now...");
os.println("VOTE_REQUEST\nPlease enter COMMIT or ABORT to proceed
: ");
for(int i=0; i<(ser.t).size(); i++)
{
if((ser.t).get(i)!=this)
{
((ser.t).get(i)).os.println("---A new user "+name+" entered the Appilcation---
");
} } while
(true) {
line = is.readLine();
if(line.equalsIgnoreCase("ABORT"))
{
System.out.println("\nFrom '"+clientIdentity+"' : ABORT\n\nSince aborted we
will not wait for inputs from other clients.");
System.out.println("\nAborted...."); for(int i=0; i<(ser.t).size(); i++)
{
((ser.t).get(i)).os.println("GLOBAL_ABORT");
((ser.t).get(i)).os.close();
((ser.t).get(i)).is.close();
}
break;
}
if(line.equalsIgnoreCase("COMMIT"))
{
System.out.println("\nFrom '"+clientIdentity+"' : COMMIT");
if((ser.t).contains(this))
{
(ser.data).set((ser.t).indexOf(this), "COMMIT");
for(int j=0;j<(ser.data).size();j++)
{
if(!(((ser.data).get(j)).equalsIgnoreCase("NOT_SENT")))
{
ser.inputFromAll=true
; continue; } else {
ser.inputFromAll=fals
e;
System.out.println("\nWaiting for inputs from other clients.");
break;
}}
if(ser.inputFromAll)
{
System.out.println("\n\nCommited...."); for(int
i=0; i<(ser.t).size(); i++)
{
((ser.t).get(i)).os.println("GLOBAL_COMMIT");
((ser.t).get(i)).os.close();
((ser.t).get(i)).is.close();
}
break;
}
}//if t.contains
}//commit }//while
ser.closed=true;
clientSocket.close()
;
}
catch(IOException e)
{
};
}
}
IMPLEMENTATION:
Windows XP
Control Panel -> Network Connections -> Right Click on LAN -> Properties -> TCP/IP
Properties
IP Address: 192.168.x.30
Subnet Mask: 255.255.255.0
Start -> Log Off -> Login again To implement above changes
RHEL6
Windows XP
RHEL6
Windows XP
Start -> Run: \\192.168.x.10 Access RHEL6 on Windows XP. Can access
RHEL6 on Windows XP with samba user ty and
its password. Will display the server but with no
contents as shares have not been created.
RHEL 6
[ns]
path=/ns
:wq
Save
Restart service to implement changes
service smb restart
made in configuration file
testparm If service is successfully restarted, will
display parameters set in configuration
file
Windows XP
RHEL6
RHEL6
Windows XP
RHEL6
:wq Save
Windows XP
Start -> Run: \\192.168.x.10 Access RHEL6 on Windows XP. Will not prompt for
user name and password as Windows login user name and password is same as
samba user and password Close the Window
RHEL6
RHEL6
Save
Restart service to implement changes made in
service smb restart
configuration file
testparm If service is successfully restarted, will display
parameters set in configuration file
Windows XP
RHEL6
vim /etc/samba/smb.conf
Edit configuration file of Samba Server
Append the following contents
[java]
path=/java
:wq Save
service smb restart Restart service to implement changes made in
configuration file
testparm If service is successfully restarted, will display
parameters set in configuration file
Windows XP
RHEL6
:wq Save
service smb restart Restart service to implement changes made in
configuration file
testparm If service is successfully restarted, will display
parameters set in configuration file
Windows XP
Start -> Run: \\192.168.x.10 Access RHEL6 on Windows XP. Will display
share ‘java’ but if you try to access it, will prompt
for user name and password as user the current
IP Address is 192.168.11.30, which is denied access
Click on Cancel
Close the Window
Windows XP
RHEL6
mkdir bscit
exit Exit from the shared folder
mount //192.168.x.30/la /data Mount Windows shared folder on local directory
cd /data touch
l1 l2 l3 cd
~/Desktop
umount /data
Windows XP
RHEL 6
service rpcbind restart The rpcbind utility maps RPC services to the ports on
which they listen. Because RPC-based services rely on
rpcbind to make all connections with incoming client
requests, rpcbind must be available before any of these
services start.
RHL9
NFS Servers
mkdir /a /z
showmount -e 192.168.x.10 Show NFS Exports
showmount -d 192.168.x.10 Show locally mounted NFS Exports
Automount Service
RHL9
mkdir /linux
chmod a+w /linux Assign write permission on /linux to all vim
/etc/auto.master Edit master map file
/linux /etc/auto.lin Mount point and path of secondary map file
:wq Save
vim /etc/auto.lin Secondary map file
:wq Save
service autofs start Start automount service
service autofs status Displays configured and active mount points cd /linux/la
rm -rf a User can perform read write operations as mount is
rw mkdir ty cd ~
service autofs stop Stop automount service service autofs
status There will be no active mount points cd /linux/la
Error as subdirectory la is available only
when automount is on
RHEL6
ls /abc