Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Ex. No 3 TCP programs a.

Program to Implement Chatting Application Aim To Write a C++ program to prepare Students Report using Simple Class with primitive and array data types Algorithm 1. Start 2. Create necessary input and output streams 3. Create a socket connection from user1 to the user2 with corresponding IP address and port number 4. Get any string from the user1 side console 5. Pass this string to the user2 which prints in the console of user2 6. Read some other string from the user2 side sockets input stream. 7. Pass this string to the user1 which prints in the console of user 8. Repeat the same until exit command 9. Stop Program User1 import java.io.*; import java.net.*; class user1 { public static void main(String arg[]) throws Exception { String sentence, newsentence; DataInputStream in=new DataInputStream(System.in); Socket cs=new Socket("10.1.1.204",6789); DataInputStream inp=new DataInputStream(cs.getInputStream()); DataOutputStream out=new DataOutputStream(cs.getOutputStream()); do { System.out.print("User1:"); sentence=in.readLine(); if(sentence.compareTo("exit")!=0) { out.writeBytes(sentence+'\n'); newsentence=inp.readLine(); System.out.println("User2:"+newsentence); } }while(sentence.compareTo("exit")!=0); cs.close(); } }

User 2 import java.io.*; import java.net.*; class user2 {

You might also like