Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Department of Computer Science & Engineering

Course Title: Parallel Processing and Distributed System Lab


Course Code: CSE 434

Lab Report

Submitted by Submitted to
Name: Md. Sabbir Hossain Mohammad Kasedullah
ID: 191311129 Lecturer, Dept. CSE, VU
Section: A (12th Tokey Ahmed
Semester) Lecturer, Dept. CSE, VU
Batch: 20th Batch

Signature

Date of Issue: 11th April 2023 Date of Submission: 25th April 2023
Question 1:Implementation of both way
commuinication Server and Client application.
Theory: The implementation of a two-way communication server
and client application typically involves the following steps:

Define the protocol: The first step in implementing a two-way


communication server and client application is to define the
communication protocol that the two will use. This protocol
will determine the format of the messages that are exchanged
between the two, and it should be designed to be both
efficient and easy to parse.

Set up the server: The next step is to set up the server that
will handle incoming connections from clients. This typically
involves creating a listening socket that is bound to a
specific port on the server machine, and then waiting for
incoming connections.
Accept client connections: Once the server is set up, it can
start accepting incoming connections from clients. When a
client connects to the server, the server should create a new
thread or process to handle that connection, so that it can
continue to accept new connections.

Implement the client: The client application should be


designed to connect to the server and send messages according
to the protocol that was defined earlier. It should also be
able to receive messages from the server and respond
appropriately.
Send and receive messages: Once both the server and client are
set up and connected, they can start exchanging messages. The
client can send messages to the server, and the server can
respond with messages of its own. This two-way communication
should continue until one side decides to disconnect.

Handle errors: It's important to handle errors that may occur


during the communication process, such as network errors,
connection drops, or invalid messages. Proper error handling
can help ensure that the application is robust and reliable.

Requirement:
1.Java Development Kit (JDK)
2.Notepad

Implementation Code:

For Server:
import java.net.*;
import java.io.*;

public class Server


{
public static void main(String args[]) throws
Exception
{
ServerSocket ss = new ServerSocket(6666);
Socket s =ss.accept();

DataInputStream din = new


DataInputStream(s.getInputStream());
DataOutputStream dout = new
DataOutputStream(s.getOutputStream());
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));

String str="",str2="";

while(!str.equals("stop"))
{
str=din.readUTF();
System.out.println("Client: " +str);
str2 = br.readLine();
dout.writeUTF(str2);
dout.flush();

din.close();
dout.close();
s.close();
ss.close();
}

}
For Client:
import java.net.*;
import java.io.*;

public class Client


{
public static void main(String args[]) throws
Exception
{
Socket s = new Socket("localhost",6666);
DataInputStream din = new
DataInputStream(s.getInputStream());
DataOutputStream dout = new
DataOutputStream(s.getOutputStream());

BufferedReader br = new BufferedReader(new


InputStreamReader(System.in));

String str="",str2="";

while(!str.equals("stop"))
{
str=br.readLine();
dout.writeUTF(str);
dout.flush();
str2=din.readUTF();
System.out.println("Server: " +str2);
}
din.close();
s.close();
}
}
}

Experimental Output:

You might also like