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

Sweet and Sour Mango Pickle (Gol Keri)

Blog banner

Save Girl Child

Blog banner

A Happier Workplace Starts with Healthy Lunches by Meal Maharaj

Blog banner

Memory management

Blog banner

Denial-of-Service and Distributed Denial-of-Service Attack Techniques

Blog banner

Cherish the Craft — Essential Tips to Maintain Your Patola Collection

Blog banner

Service transition principles

Blog banner

Decrypting Cryptocurrency: Tracing Transactions in Cyber Investigations

Blog banner

How International Schools Build Global-Minded Students through Curriculum & Activities

Blog banner

INTERRUPTS

Blog banner

Ethical Hacking

Blog banner

SQL Injection

Blog banner

On-Page SEO

Blog banner

MENDELEY

Blog banner

OS DESIGN CONSIDERATIONS FOR MULTIPROCESSOR

Blog banner

Photorec - media recovery tool

Blog banner

Memory Management in Operating System

Blog banner

To travel is to live

Blog banner

TOP 5 GAMING GADGETS (2024)

Blog banner

Deadlock Prevention

Blog banner

KAHAWA TEA

Blog banner

Threads in OS

Blog banner

Festive Ethnic Wear Guide: Patola-Inspired Looks for Every Celebration

Blog banner

LTE Technology

Blog banner

MAJOR ACHIEVEMENTS OF OS

Blog banner

Networking 101: How to Build Meaningful Connections in College

Blog banner

1.1 basic elements

Blog banner

INTRODUCTION TO C#

Blog banner

Having passion in life

Blog banner

Clarizen

Blog banner

Memory input output management

Blog banner

Smartsheet

Blog banner

Direct memory access

Blog banner

The Truth Behind Viral DIY Dental Hacks

Blog banner

Exploring Human Factors in Cyber Forensics Investigations.

Blog banner

Zero-Click Searches: How To Stay Visible In Google’s New Era

Blog banner

Rock, Paper, Scissors Game in Common Lisp

Blog banner

differentiate thinking humanly and rationally

Blog banner

Constrained Management in IT

Blog banner

Direct Memory Access

Blog banner

Cyber Forensics

Blog banner

I/O Buffering

Blog banner