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
1055 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

Multithreading in Operating System

Blog banner

How the mobile IP is used in GSM architecture.

Blog banner

Decoding Confusion Matrix

Blog banner

How Do I Get Rid of My People-Pleasing Behaviour?

Blog banner

IoT Evolution

Blog banner

Sensory Play for Toddlers: Boosting Curiosity Through Touch, Sound, and Colour

Blog banner

Mumbai famous street food

Blog banner

Understanding Univariate, Bivariate, and Multivariate Analysis in Data Science

Blog banner

Teamwork

Blog banner

Virtual Memory - Explaination, Working, Steps

Blog banner

How Social Media Algorithms Will Work in 2026?

Blog banner

Music

Blog banner

What is Minting & Mining

Blog banner

Virtualisation

Blog banner

Mumbai Metro 3

Blog banner

MODERN OPERATING SYSTEM

Blog banner

Evolution of Operating System

Blog banner

GUIDE TO GIS

Blog banner

Why Dry Fruits Make the Perfect Gifting Choice for Every Occasion?

Blog banner

FASHION

Blog banner

How to make Pancakes

Blog banner

INTERNET SECURITY

Blog banner

In the world of Technology...

Blog banner

How can parents support a child’s mental health?

Blog banner

Sweet and Sour Mango Pickle (Gol Keri)

Blog banner

Body Image and Low Self Esteem: Understanding the Emotional Impact Beyond Appearance

Blog banner

Modern Operating Systems

Blog banner

10 Types of Friends in every friend group

Blog banner

Modern operating system

Blog banner

Education?

Blog banner

A-B-C of Networking: Part-3 (Topology [Bus & Star])

Blog banner

New Horizon Europe project ‘EvoLand’ sets off to develop new prototype services.

Blog banner

MUTUAL EXCLUSION

Blog banner

OS Assignment 3

Blog banner

Digital Life And Mental Health: A Psychological Perspective in the Modern World

Blog banner

FAMILY WHERE LIFE BEGINS....

Blog banner

EVOLUTION OF MICROPROCESSOR

Blog banner

Virtual memory

Blog banner

The War With Cold On Earth

Blog banner

Blog name

Blog banner

Memory management

Blog banner

Threat management

Blog banner