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

OS Evolution Achievements

Blog banner

Explain website hacking issues

Blog banner

(Input/Output) in os

Blog banner

Note Taker App

Blog banner

Hey Aryan here

Blog banner

Bitcoin sent using radio waves! No internet!

Blog banner

Exploring Virtual Machines and Computer Forensic Validation Tools

Blog banner

Types of email

Blog banner

Famous Indian dishes that where misunderstood to be Indian

Blog banner

10 Reasons to Date a South Indian Girl

Blog banner

Decrypting Cryptocurrency: Tracing Transactions in Cyber Investigations

Blog banner

Digital Marketing

Blog banner

Memory input output management

Blog banner

Memory management

Blog banner

Data Acquisition in Cyber Forensics

Blog banner

Why Inconel 625 and Monel 400 Remain Unbeatable in Refinery Applications?

Blog banner

Hash password! Is it really secured?

Blog banner

Blockchain technology: security risk and prevention

Blog banner

Importance Of Yoga.

Blog banner

Deadlock

Blog banner

A Tourist’s Guide To Florida’s Rodeo Culture: What To Expect At The Arcadia Championship Rodeo

Blog banner

Record Blocking

Blog banner

Key to success in Sports

Blog banner

COMPUTER FORENSICS AND GRAPHICS

Blog banner

IS CONVERTING AMBITION INTO PROFESSION?

Blog banner

What does the Australian summer have in store for your oral health?

Blog banner

Uniprocessor Scheduling

Blog banner

A Traveller’s Guide to Offbeat Places in Arcadia, Florida

Blog banner

Question

Blog banner

M commerce

Blog banner

Scheduling

Blog banner

Technical SEO : Total Guide

Blog banner

Cyber Forensics in Healthcare: Protecting Patient Data and Preventing Breaches

Blog banner

Virtualization

Blog banner

ODOO

Blog banner

Digital marketing spotlight “Dove’s Real Beauty Campaign”

Blog banner

Objectives and Functions of Operating System

Blog banner

Top Career Paths After a B.Com Degree in Mumbai: What’s Next for You?

Blog banner

OS DESIGN CONSIDERATIONS FOR MULTIPROCESSOR

Blog banner

Rules and Regulations of Networking: "Standards and Protocols" - Part 2

Blog banner

Hacking of web server and application

Blog banner

Service Transition Process in ITSM

Blog banner