-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatServer.java
More file actions
29 lines (27 loc) · 820 Bytes
/
ChatServer.java
File metadata and controls
29 lines (27 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.io.*;
import java.net.*;
class ChatServer
{
public static void main(String[] args) throws Exception
{
ServerSocket ss = new ServerSocket(9999);
Socket s = ss.accept();
BufferedReader sbr = new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(s.getOutputStream());
while(true)
{
String str = sbr.readLine();
System.out.println("Client : " + str);
System.out.print("Server : ");
String ans = br.readLine();
pw.println(ans);
pw.flush();
System.out.println();
if(!str.toUpperCase().equals("BYE"));
break;
}
s.close();
ss.close();
}
}