wisemonkeys logo
FeedNotificationProfileManage Forms
FeedNotificationSearchSign in
wisemonkeys logo

Blogs

Practical Implementation of Client Server model using TCP/IP.

profile
Kiddoneeta
Oct 26, 2017
0 Likes
0 Discussions
1053 Reads
Author : Neeta Vonkamuti

Server – Client Communication using TCP/IP

Server-client model is communication model for sharing the resource and provides the service to different machines. Server is the main system which provides the resources and different kind of services when client requests to use it.

1) First open the two notepad.

A] In first notepad, type the code for  server side and save it as the same class name which you have provided in the code and with the extension .java

For Example, MyServer.java
import java.net.*; import java.io.*; class MyServer { public static void main(String args[])throws Exception { ServerSocket ss=new ServerSocket(3333); 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 says: "+str); str2=br.readLine(); dout.writeUTF(str2); dout.flush(); } din.close(); s.close(); ss.close(); }

B] In second notepad, type the code for the client side and save it as the  same class name which you have provided in the code and with the extension .java

For Example, MyClient.java
import java.net.*; import java.io.*; class MyClient { public static void main(String args[])throws Exception { Socket s=new Socket("localhost",3333); 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 says: "+str2); } dout.close(); s.close(); } }

2) Output for the code:-

A] Server-Side :

B] Client-Side :


Comments ()


Sign in

Read Next

Electronic Funds Transfer

Blog banner

Teamwork

Blog banner

Simple STEM Activities for Toddlers That Spark Curiosity

Blog banner

38_Network Sniffing Techniques_SBC

Blog banner

Memory Management Techniques

Blog banner

The Art Of Getting What You Want In Life....

Blog banner

Exploring the Power of Encase Forensic Tools: Unraveling Digital Mysteries

Blog banner

Maharashtrian culture: Tradition, Art, Food

Blog banner

MENDELEY

Blog banner

Partnership in Learning: How Parent Involvement Shapes a Child’s Early Education

Blog banner

It's all about our Brain.- The Brain Metaphor

Blog banner

Real-Time Operating Systems (RTOS) Deep Explanation

Blog banner

Cache memory

Blog banner

Virtual memory in Operating System

Blog banner

Getting started with Android Studio

Blog banner

LinkedIn

Blog banner

Street foods

Blog banner

Access management

Blog banner

Wrike

Blog banner

Top 3 Places To Stay In Vienna

Blog banner

child Labour

Blog banner

differentiate thinking humanly and rationally

Blog banner

Unlocking the Secrets: Basic Operations of Computer Forensic Laboratories

Blog banner

Data-Driven Prediction of Virtual Item Prices in Online Games

Blog banner

How Laughing Gas Makes Your Dental Visit So Much Easier

Blog banner

Full Disk Encryption

Blog banner

Financial Fraud Detection

Blog banner

This too shall pass

Blog banner

BrainGate Technology

Blog banner

KEAP MANAGEMENT SYSTEM

Blog banner

What is Virtual Memory

Blog banner

10 Things To Do On Valentine's Day If You're Single

Blog banner

Time Series Analysis

Blog banner

The Truth Behind Viral DIY Dental Hacks

Blog banner

How covid-19 impacted Social media ad spend forecast globally

Blog banner

Improving the Accuracy of GPS and GNSS

Blog banner

Which Smartphone Company Has the Largest Market Share in India?

Blog banner

Digital Marketing - The new way to reach end consumer

Blog banner

Data Science in Predictive Analytics: Transforming Business Decision-Making

Blog banner

A buffer overflow

Blog banner

objectives and functions of operating system

Blog banner

Modern operating system

Blog banner