Chat Server
Chat Server
Chat Server
utputStream os = s.getOutputStream();
O
BufferedReader br1 = new BufferedReader(
new InputStreamReader(s.getInputStream())
);
PrintStream ps = new PrintStream(os);
do{
System.out.print("Client: ");
String msg = br.readLine();
ps.println(msg);
String res = br1.readLine();
System.out.println("Server Send:"+res+"\n\n");
}
while(true);
}
};
ServerSide.java
import java.net.ServerSocket;
import java.net.Socket;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.InputStreamReader;
public class ServerSide
{
public static void main(String[] args) throws IOException
13
{
erverSocket s = new ServerSocket(2019);
S
System.out.println("Server Started, waiting for client");
Socket s1 = s.accept();
// Client Send
BufferedReader br = new BufferedReader(
new InputStreamReader(s1.getInputStream())
);
OutputStream out = s1.getOutputStream();
PrintStream ps = new PrintStream(out);
do{
String res = br.readLine();
ystem.out.print("Server: ");
S
String msg = br1.readLine();
System.out.print("\n\n");
ps.println(msg);
}
while(true);
}
}
Output: