//Client file
import java.*;
import java.io.*;
import java.net.*;
import java.util.*;

class client_s
 {
 public static void main(String arg[]) throws Exception
 {
 
 Socket sd = new Socket("Localhost",6666);
 DataOutputStream dos = new DataOutputStream(sd.getOutputStream());
 DataInputStream dis = new DataInputStream(sd.getInputStream());
 Scanner sc=new Scanner (System.in); 
 String str1="", str2="";
 System.out.println("..........................................\n");
 System.out.println(": To Stop Conversation Type 'stop' :");
 System.out.println("..........................................\n");
 
 System.out.print("Start Talking with Server : ");

 while(!str1.equals("stop") && !str2.equals("stop"))
 {
 str1=sc.nextLine();
 dos.writeUTF(str1);
 dos.flush(); 
 
 str2 = dis.readUTF();
 System.out.print("\nServer says : "+str2);
 System.out.print("\n\nReply : ");
 }
 dos.close(); 
 sd.close();
 }
 }

//Server file
import java.*;
import java.io.*;
import java.net.*;
import java.util.*;

class server_c
{
 public static void main(String arg[]) throws Exception
 {
 Scanner sc=new Scanner(System.in);
 String str1="", str2="";
 
 ServerSocket ss = new ServerSocket(6666);
 Socket sd = ss.accept();
 DataInputStream dis = new DataInputStream(sd.getInputStream());
 DataOutputStream dos = new DataOutputStream(sd.getOutputStream());
 System.out.println("....................................................\n");
 System.out.println(": To Stop Conversation Type 'stop' :");
 System.out.println("....................................................\n");

 while(!str1.equals("stop") && !str2.equals("stop"))
 {
 str1 = dis.readUTF(); 
 System.out.println("\nClient says : "+str1);
 System.out.println("");
 System.out.print("Reply : ");
 str2 = sc.nextLine();
 dos.writeUTF(str2);
 dos.flush();
 }
 dos.close();
 sd.close(); 
 ss.close(); 
 }
 }
OUTPUT

Communication between Client-Server :

Click on Image to open 

client_server

Leave a Reply

Subscribe to Posts | Subscribe to Comments

All Notes on BCA

All Notes  on BCA
BCA all subjects notes

Total Pageviews

Translate

Powered by Blogger.

Copyright © All Notes on BCA