123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Computer-Programming >> View Article

Practical Implementation Of Client Server Model Using Tcp/ip

Profile Picture
By Author: Wisemonkeys
Total Articles: 263
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

Server — Client Communication using TCP/IP

Server-client model is a communication model for sharing the resource and providing the service to different machines. The server isthe main system that provides the resources and different kinds of services when a client requests to use it.

1) First open the two notepads.
A] In the 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 the ...
... 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 :

It is said that “Knowledge is Power” and Wisemonkeys(https://wisemonkeys.info/) is the ideal platform to prove this right where this blog was posted. Additionally, when knowledge is free it should be shared. Therefore, keeping this in mind Wisemonkeys an LMS platform is developed so that people can exchange their ideas, knowledge, and experiences for the wise Gen Z.

SIGN UP(https://wisemonkeys.info/) TODAY and upgrade your knowledge base.

Total Views: 378Word Count: 269See All articles From Author

Add Comment

Computer Programming Articles

1. Helping Travel Leaders Deploy Hotel Rate Comparison Automation
Author: webfusion

2. Drive Automated Website Data Collection For Profitable Roi
Author: webfusion

3. How To Monitor Competitor Stock Availability Across Online Retailers
Author: KVETOIQ

4. How Professional It Consultants In Nyc Help Businesses Improve Technology
Author: Sam Vohra

5. How Do You Choose A Commercial Display Fridge For A Supermarket?
Author: Sanjiv Chaudhary

6. Product Matching At Scale: How Retailers Match Exact Products, Variants & Comparable Items Across Marketplaces
Author: KVETOIQ

7. Enterprise Web Crawling At Scale: 10 Requirements For Reliable, Continuously Refreshed Web Data
Author: KVETOIQ

8. Quick Commerce Data Scraping: How Businesses Can Turn Real-time Market Data Into A Competitive Advantage
Author: KVETOIQ

9. Best Data Extraction Companies In India (2026): 8 Managed Providers For Custom Business Data
Author: KVETOIQ

10. Ecommerce Assortment Intelligence: How Retailers Track Product Gaps, New Launches & Category Changes
Author: KVETOIQ

11. Simple Google Maps Business Data Scraping For Global Reach
Author: webfusion

12. Amazon Price Monitoring: How Brands Track Competitor Prices, Discounts & Stock Changes
Author: KVETOIQ

13. Product Engineering Solutions In The Usa: Building Scalable And Innovative Digital Products
Author: John Smith

14. How An Emergency Assembly Point Helps Organize Workplace Evacuations
Author: How an Emergency Assembly Point Helps Organize Wor

15. How To Improve Workplace Safety Awareness Through Daily Practices
Author: scrum

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: