Skip to content

Instantly share code, notes, and snippets.

@vnkdj5
Last active June 29, 2017 06:40
Show Gist options
  • Save vnkdj5/df918a56260a29b169cc717e282e5d7f to your computer and use it in GitHub Desktop.
Save vnkdj5/df918a56260a29b169cc717e282e5d7f to your computer and use it in GitHub Desktop.
Echo Sever (Chat Server)
import java.net.*;
import java.io.*;
public class Server {
public static void main(String args[]) throws Exception,UnknownHostException{
ServerSocket ss=new ServerSocket(8088);
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!="stop")
{
System.out.println("Waiting for client's Reply...");
str=din.readUTF();
System.out.println("Client: "+str);
System.out.println("Enter Message:");
str2=br.readLine();
dout.writeUTF(str2);
dout.flush();
}
din.close();
s.close();
ss.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment