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

Cache Memory(142)

Blog banner

Overcoming the bedtime brushing Battle with Dr. Roxanne Irani, Dentist in Maroubra

Blog banner

Esri India launches Policy Maps.

Blog banner

Race Condition

Blog banner

Busted : Common Web Security Myths

Blog banner

From Procrastinator to Performer: How to Beat the Last-Minute Rush

Blog banner

Advantage of freedom

Blog banner

Functions of operating system

Blog banner

OS Assignment-3

Blog banner

CRISP-DM Methodology

Blog banner

Race Conditions

Blog banner

Software Piracy & Online Data Protection in Digital World

Blog banner

Technical SEO : Total Guide

Blog banner

Data Acquisition in Cyber Forensics

Blog banner

The Power of Forensic Watermarking in the Fight Against Content Piracy

Blog banner

What Makes a School Safe, Supportive, and Student-Friendly

Blog banner

Explain Kernel in OS

Blog banner

DATA VAULT

Blog banner

Article on IT development trends

Blog banner

Is Brushing After Eating Damaging Your Teeth? (Fact or Myth)

Blog banner

How to Prepare Your Child for Their First Day of School?

Blog banner

Social Media.

Blog banner

Brain wash of social media

Blog banner

BUFFER OVERFLOW_142

Blog banner

Security in Operating Systems

Blog banner

How to use GIT & GITHUB

Blog banner

Uniprocessor Scheduling

Blog banner

How To Invest In Indian Stock Market @ BSE & NSE ~ Tutorial 3

Blog banner

Best password managers: Reviews of the top products

Blog banner

The Role of Data Provenance and Lineage in Modern Data Science

Blog banner

The Role of Teachers in Building a Child’s Confidence

Blog banner

Virtual Memory - Explaination, Working, Steps

Blog banner

Maharashtrian culture: Tradition, Art, Food

Blog banner

MODERN OPERATING SYSTEMS

Blog banner

10 Unknown facts about India's Independence

Blog banner

What are NFT s?

Blog banner

Salt, Sand, and Smiles: Does the Maroubra Lifestyle Affect Your Enamel?

Blog banner

Policies for Service Transition

Blog banner

Rock, Paper, Scissors Game in Common Lisp

Blog banner

IT service level agreement

Blog banner

Boxing

Blog banner

KASHMIR TRIPS

Blog banner