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

Music

Blog banner

My Favorite Sportsperson

Blog banner

Multiprocessor and Multicore Organization

Blog banner

Data-Driven Prediction of Virtual Item Prices in Online Games

Blog banner

Social Engineering Deceptions and Defenses

Blog banner

The New Classic: Indo Western Patola Outfits for Today’s Woman

Blog banner

Little Habits, Big Impact: Daily Preschool Routines That Shape the Future

Blog banner

Operating system

Blog banner

Models of Information Security.

Blog banner

INTRODUCTION

Blog banner

Developments in Modern Operating Systems

Blog banner

Deadlocks in Operating System

Blog banner

Digital black market or dark net poses a national security threat?

Blog banner

RAID

Blog banner

Data Mining

Blog banner

SQL Injection Techniques

Blog banner

A small world of Sockets

Blog banner

What is Segmentation?

Blog banner

Data Security must be your Priority!

Blog banner

This too shall pass

Blog banner

GIS

Blog banner

Top 4 Places To Stay In Copenhagen

Blog banner

Cybersecurity Standards for Automotive

Blog banner

AI and Data Science: Revolutionizing Industries

Blog banner

How to kiss

Blog banner

Key to success in Sports

Blog banner

Method of Evaluating Information Security Level in an Organization

Blog banner

Pilgrimage at LOC: A privilege and a paradox

Blog banner

Simple STEM Activities for Toddlers That Spark Curiosity

Blog banner

Phishing

Blog banner

Why Summer Break Is Important for Emotional and Cognitive Growth?

Blog banner

Title: Modern Operating Systems: Powering the Digital Era

Blog banner

Malware

Blog banner

Remote Work in 2026

Blog banner

Article on different management system

Blog banner

The Story of Saunf: How This Tiny Seed Became an Everyday Kitchen Favourite

Blog banner

Ghee vs. Coconut Oil vs. Mustard Oil: Which Cooking Fat Wins for Indian Food?

Blog banner

Modern Operating System

Blog banner

Session Hijacking Techniques

Blog banner

FOMO Fear of Missing Out: When Comparison Steals Your Peace of Mind

Blog banner

Scheduling

Blog banner

Efficiency of SQL Injection Method in Preventing E-Mail Hacking

Blog banner