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

On-Page SEO

Blog banner

Deadlock and Starvation

Blog banner

Linux 94

Blog banner

security requirements for safe e-payment

Blog banner

(Input/Output) in os

Blog banner

Hubspot

Blog banner

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

Blog banner

Modern operating system

Blog banner

Types of Malware in Cyber Security

Blog banner

Paralysis/Paralysis Stroke

Blog banner

Threads

Blog banner

Why Should You Schedule Tweets on Twitter?

Blog banner

Importance of internet

Blog banner

Scheduling

Blog banner

Deadlock in Operating System

Blog banner

How to insert contacts in zoho crm using php

Blog banner

What is Vishing?

Blog banner

Drawing tips for a beginner

Blog banner

10 Unsolved Mysteries all over the world

Blog banner

Risk mitigation and management

Blog banner

Memory Management - operating system

Blog banner

Data Science in Everyday Life (like a phone, shopping cart, or social media icons)

Blog banner

Explain DBMS in Brief

Blog banner

Understanding Business Layer in Data Science

Blog banner

AN EVENT-BASED DIGITAL FORENSIC INVESTIGATION

Blog banner

Data carving - using hex editor

Blog banner

LinkedIn: Watch out for these 7 upcoming updates in 2023

Blog banner

10 Survival Tips that might save your life

Blog banner

Types of Hackers

Blog banner

Uniprocessor Scheduling

Blog banner

Why Are So Many Adults Getting Diagnosed with ADHD?

Blog banner

Network Forensics Tools and Techniques

Blog banner

BharatPe

Blog banner

File Management In OS

Blog banner

History of Money

Blog banner

City of Mumbai (Bombay):

Blog banner

What is online marketing and why do you need to know about it ?

Blog banner

Modern Operating System

Blog banner

PPT methodology

Blog banner

RAID and It's Levels

Blog banner

Digital Marketing - The new way to reach end consumer

Blog banner

Telegram and it's features

Blog banner