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

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

Blog banner

Oracle Corporation

Blog banner

RSA (Rivest-Shamir-Adelman) Algorithm

Blog banner

Modern Operating System - Khush bagaria

Blog banner

Cryptanalysis tool

Blog banner

Social Media.

Blog banner

'C', 'C++' and 'Java': Head-to-Head

Blog banner

Time Series Analysis

Blog banner

Virtual Machine

Blog banner

Beatbox

Blog banner

OS Assignment-3

Blog banner

Security in Operating Systems

Blog banner

File Management system

Blog banner

ROLE OF THE COMPUTER FORENSICS TOOLS AND TECHNIQUES

Blog banner

Old age lifestyle

Blog banner

The Bold Digital Marketing Moves That Made Durex India’s Second-Largest Condom Brand

Blog banner

Blockchain in IoT Applications

Blog banner

Smart Homes | Zigbee Alliance

Blog banner

Explain website hacking issues

Blog banner

Computer Security

Blog banner

Study on cyber and network forensic in computer security management

Blog banner

DMZ: Your Secret Weapon for Data Security

Blog banner

Linux Memory Management

Blog banner

Memory Management

Blog banner

Types of Threads

Blog banner

Memory management

Blog banner

Note Taker App

Blog banner

Define Instagram.

Blog banner

Threats To Computer System

Blog banner

FRIENDSHIP

Blog banner

Developments in Modern Operating Systems

Blog banner

Android Application Components and Activity Lifecycle

Blog banner

Computer security techniques

Blog banner

Predicting Student Performance with Data Science

Blog banner

Solitary Play Activities for Preschoolers: Types and Benefits

Blog banner

Incorporating Automation into Digital Forensics.

Blog banner

How to setup a professional looking business account on Instagram?

Blog banner

objectives and functions of operating system

Blog banner

It's all about our Brain.- The Brain Metaphor

Blog banner

clock

Blog banner

Man VS Nature

Blog banner

The most common internet security threats

Blog banner