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

The Features of Blockchain

Blog banner

Strengthening Active Directory Security

Blog banner

Office Lunch Problems in Mumbai and How Tiffin Services Solve Them

Blog banner

File management

Blog banner

Networking 101: How to Build Meaningful Connections in College

Blog banner

MoSCoW METHOD IN DATA SCIENCE

Blog banner

Product Discount Calculator

Blog banner

Fashion design

Blog banner

MULTITHREADING:ENHANCEING PERFORMANCE AND EFFICIENCY IN COMPUTING

Blog banner

Virtual Machine's

Blog banner

How to Run your First android App

Blog banner

The evolution of OS

Blog banner

Whatsapp Messenger

Blog banner

Blockchain Transactions

Blog banner

Instagram

Blog banner

Buffer overflow

Blog banner

IoT Architecture Based Security

Blog banner

Deadlock

Blog banner

Modern Operating Systems.

Blog banner

What is service level Agreement?

Blog banner

Different memory allocation strategies

Blog banner

India Digital Personal Data Protection Act, 2023

Blog banner

TRAIN TRAVELING

Blog banner

What's Better : Supervised or Unsupervised Learning

Blog banner

Guidelines for a Low sodium Diet.

Blog banner

Disk scheduling

Blog banner

VIRTUAL MACHINE

Blog banner

10 Reasons Why Guy BestFriends are the Must in Every Girl's Life

Blog banner

Direct Memory Access

Blog banner

MY FIRST BLOG?

Blog banner

Top 5 Tech Innovations of 2018

Blog banner

To-Do List In LISP

Blog banner

Vulnerability Assessment

Blog banner

Ransomware

Blog banner

VIRTUAL MACHINES

Blog banner

Modern Operating Systems

Blog banner

Starvation

Blog banner

BENIFITS OF YOGA

Blog banner

Threads

Blog banner

Service Design Model

Blog banner

Memory Management

Blog banner

File Systems in OS.

Blog banner