Skip to content

Instantly share code, notes, and snippets.

@vnkdj5
Created June 29, 2017 06:42
Show Gist options
  • Save vnkdj5/5ec9a736efcca9fc01897a12688b95c2 to your computer and use it in GitHub Desktop.
Save vnkdj5/5ec9a736efcca9fc01897a12688b95c2 to your computer and use it in GitHub Desktop.
Client Application for Echo (Chat) Server
import java.net.*;
import java.io.*;
public class Client {
public static void main(String[] args) throws Exception {
Socket s=new Socket("localhost",8088);
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")){
System.out.println("\nEnter Response: ");
str=br.readLine();
dout.writeUTF(str);
dout.flush();
System.out.println("Waiting for Server's Reply...");
str2=din.readUTF();
System.out.println("Server says: "+str2);
}
dout.close();
s.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment