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

How to Encrypt and Decrypt Using GNU PGP

Blog banner

How User Data Shapes Personalised Campaigns

Blog banner

Metasploit

Blog banner

Health and fitness

Blog banner

What is Vishing?

Blog banner

LIFEHACKER

Blog banner

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

Blog banner

Linux Memory Management

Blog banner

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

Blog banner

Meshoo

Blog banner

Riddhi Miyani 53003220140

Blog banner

THE ROLE OF CYBER FORENSICS IN CRIMINOLOGY

Blog banner

Memory Management of Operating System(OS)

Blog banner

Optimization of operating system design

Blog banner

A Review on Data Acquisition in Cyber Forensics

Blog banner

"Audit" In Data Science

Blog banner

Service Transition Process in ITSM

Blog banner

Reconnaissance

Blog banner

Apache Kafka

Blog banner

GUIDE TO GIS

Blog banner

Simple Ways of Avoiding Basic Mistakes in Smart Phone Security

Blog banner

Blockchain uses and use cases

Blog banner

OPERATING SYSTEM OBJECTIVES AND FAULT TOLERENCE.

Blog banner

The Golden Temple , Amritsar

Blog banner

Apple

Blog banner

Scala - a programming tool

Blog banner

Memory management

Blog banner

Race Condition

Blog banner

SPAM

Blog banner

I/O buffer and its techniques

Blog banner

Modern Operating Systems.

Blog banner

Difference Between Classification And Clustering

Blog banner

Basic Security For SOAP Services

Blog banner

HUBSPOT

Blog banner

Full Disk Encryption on Digital Forensics

Blog banner

Atlantis - The Lost Island.........

Blog banner

Rapido

Blog banner

E-Cash (Electronic Cash)

Blog banner

Buffering

Blog banner

The Role of Summer Camps in Early Childhood Development

Blog banner

PROCESS STATES OF OPERATING SYSTEM

Blog banner

Threads

Blog banner