ALL >> Computer-Programming >> View Article
Practical Implementation Of Client Server Model Using Tcp/ip
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.
Add Comment
Computer Programming Articles
1. Which Are The Best Java Coding Classes In Bhopal?Author: Shankar Singh
2. Warehouse Management In Zambia: Essential Features To Look For
Author: Doris Rose
3. Ecommerce Web Design And Development In Melbourne With The Merchant Buddy
Author: themerchantbuddy
4. Why Website Maintenance Is Crucial For Business Success
Author: Yogendra Shinde
5. Boost Your Business With Smart Invoice Pos Software In Zambia
Author: Cecilia Robert
6. How Stablecoin Development Ensures Stability And Security?
Author: Michael noah
7. Công Cụ Tính Chiều Cao Chuẩn Từ Minbin Tool: Đo Lường Và Cải Thiện Chiều Cao Hiệu Quả
Author: KenJi123
8. How To Make A Courier App For Courier Delivery And Tracking Service
Author: Deorwine Infotech
9. Reputation Management In The Digital Age: Protecting And Enhancing Your Law Firm’s Image
Author: jamewilliams
10. What Features Should I Look For In Wordpress Ecommerce Plugins?
Author: Rocket Press
11. Staying Updated With The Latest Gaming News
Author: Next Tech Plus
12. Game Development: Evolving Technologies And New Horizons
Author: Rick John
13. Why Svelte Is The Most In-demand Framework For Web Development?
Author: Why Svelte Is The Most In-Demand Framework For Web
14. Maximizing Ebay Sales With Maropost/neto And Pursuit Info Solutions
Author: rachelvander
15. The Importance Of Software Testing: Ensuring Quality In Development
Author: John Mathew