Building a Client-Server Model on different computers.

Aim: Write a program to Build Client-Server Model on different computers.

Apparatus (Software): Eclipse/ Netbeans

Procedure: Following should be studied to understand this practical

What a client is and what is a server?

• Client - A client is a single-user workstation that provides presentation services and the
appropriate computing, connectivity and the database services and the interfaces relevant to the
business need.
• Server- A server is one or more multi-user processors with share memory providing computing,
connectivity and the database services and the interfaces relevant to the business need.
Image result for client server architecture
Fig: Client Server Model

The protocol is the client requests the services from the server; the server processes the request and returns the result to the client. The communication mechanism is a message passing InterProcess communication (IPC) that enables the distributed placement of the client and server processes .

  The distinguishing characteristics of the Client/Server systems are:

1. Service: The client/server is primarily a relationship between processes running on separate machines. The server process is a provider of services. The client is a consumer of services. Inessence, client/server provides a clean separation of function based on the idea of service.

2. Shared Resources: A server can service many clients at the same time and regulate their access to shared resources

3. Asymmetrical protocols: There is a many-to-one relationship between the clients and the server.Clients always initiate the dialog by requesting a service. Servers are passively awaiting request from the clients. In some cases a client may pass a reference to a callback object when it invokes a service. This lets the server call back the client. So the client becomes a server.

4. Transparency of location: The server is a process that can reside on the same machine as the client or on a different machine across a network. Client/Server software usually masks the location of the server from the clients by the redirecting the service calls when needed. A program can be aclient, a server, or both.

5. Mix-and-match: The ideal client/server software is independent of hardware or operating system software platforms. You should be able to mix-and-match client and server platforms.

6. Message-based exchanges: Clients and servers are loosely coupled systems that interact through a message-passing mechanism. The message is the delivery mechanism for the service request and replies.

7. Encapsulation of services: The server is a specialist. A message tells a server is requested; it is then up to the server to determine how to get the job done. Servers can be upgraded without affecting the clients as long as the published message interface is not changed.

8. Scalability: Client/Server systems can be scaled horizontally or vertically. Horizontal scaling means adding or removing client workstations with only a slight performance impact. Vertical scaling means either migrating to a larger and faster server machine or distributing the processing load across multiple servers.

9. Integrity: The server code and server data is centrally managed, which results in cheaper maintenance and the guarding of shared data integrity. At the same time, the clients remain personal and independent.

Program

A Java Program Implementing a Simple Message Passing Socket Program Connecting Server with Client.

//CLEINT PROGRAM

import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;


public class Client
{
public static void main(String a[])throws IOException
{
Socket s=new Socket("LocalHost",8000);
DataInputStream in=new DataInputStream(s.getInputStream());
DataInputStream inn=new DataInputStream(System.in);
PrintStream dos=new PrintStream(s.getOutputStream());
while(true)
{
String str=in.readLine ();
System.out.println("msg received:"+str);
if(str.equals("bye"))
{
s.close();
break;
}
System.out.println("enter the msg to send: ");
String str1=inn.readLine ();
dos.println(str1);
if(str1.equals("bye"))
{
s.close();
break;
}
}
}

//SERVER PROGRAM

import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server
{
public static void main(String a[])throws IOException
{
ServerSocket ss=new ServerSocket(8000);
Socket s=ss.accept();
PrintStream dos=new PrintStream(s.getOutputStream());
DataInputStream in=new DataInputStream(System.in);
DataInputStream inn=new DataInputStream(s.getInputStream());
while(true)
{
System.out.println("enter the msg to send: ");
String str=in.readLine ();
dos.println(str);
if(str.equals("bye"))
{
ss.close();
break;
}
String str1=inn.readLine ();
System.out.println("msg received: \n"+str1);
if(str1.equals("bye"))
{ss.close();
break;
}
}
}
}

OUTPUT:

//SERVER OUTPUT
enter the msg to send: hii
msg received: heya
enter the msg to send: hiii nice to see u..
msg received: same here..
enter the msg to send: bye

//CLIENT OUTPUT:-
msg received: hii
enter the msg to send: heya
msg received: hiii nice to see u..
enter the msg to send: same here..
msg received: bye


Comments

Popular posts from this blog

Study of Differenet Network Types and Different Types of Network Cables and Practically Implement the Cross-Wired cable using Clamping Tool.

MYSQL COMMANDS

IPv4 Classes and Subnetting