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

What is HTML?

Blog banner

Threads

Blog banner

Deadlock

Blog banner

Cache Memory

Blog banner

MAILFENCE

Blog banner

Human Error: The weakest link in Cybersecurity

Blog banner

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

Blog banner

PROCESS STATES OF OPERATING SYSTEM

Blog banner

Virtualization

Blog banner

Memory managment

Blog banner

Data Warehouse Bus Matrix

Blog banner

What is a Dumpster Diving Attack?

Blog banner

FAMILY WHERE LIFE BEGINS....

Blog banner

Jira service Management

Blog banner

My Favorite Country

Blog banner

A-B-C of Networking: Part-1 (Basics)

Blog banner

Discover The Top 3 Places To Stay in London

Blog banner

Security Issues

Blog banner

Optimization of operating system design

Blog banner

Challenges of Digital forensics in cloud computing environment

Blog banner

Banaras

Blog banner

Virtualisation

Blog banner

A-B-C of Networking: Part-2 (Components)

Blog banner

Have You Explored India Yet?

Blog banner

Predictive Analytics: How Data Science Predicts Trends(Weather ,Stock Market,Sales Forecasting ).

Blog banner

Cache memory

Blog banner

OPERATING SYSTEM OBJECTIVES AND FAULT TOLERENCE.

Blog banner

Next time you click on "Remind me later", think twice!

Blog banner

Windows Operating System

Blog banner

Uniprocessor scheduling

Blog banner

Dekkers Algorithm : Ensuring Safe Process Synchronization

Blog banner

SMARTSHEET MANAGEMENT SYSTEM

Blog banner

What if COVID does not exist!

Blog banner

Daycare Centres Help Children Transition into Structured Learning

Blog banner

You'll get to know about Pankaj Negi

Blog banner

Evolution of Operating Systems

Blog banner

S-Tool : Steganography

Blog banner

Operating system

Blog banner

What is Spyware?

Blog banner

BITCOIN WALLET

Blog banner

Development Of Modern Operating System

Blog banner

What's Better : Supervised or Unsupervised Learning

Blog banner