-
Notifications
You must be signed in to change notification settings - Fork 0
/
BiServer.java
48 lines (45 loc) · 1.46 KB
/
BiServer.java
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//Input OutPut Class for Bufferedreader&PrintWriter Classes
/*
@author:shamil-t
*/
import java.io.*;
//Network Class for Socket&ServerSocket
import java.net.*;
class BiServer
{
public static void main(String a[]) throws Exception
{
//Establishing Connection
ServerSocket ss = new ServerSocket(9000);
System.out.println("Waiting for Client");
Socket s = ss.accept();
System.out.println("Client Connected");
//For Reading Message from Client
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
//For Reading Message from Keyboard
BufferedReader ir = new BufferedReader(new InputStreamReader(System.in));
//Sending Data to the Client
PrintWriter pr = new PrintWriter(s.getOutputStream(),true);
//while loop for sending and reading messages
while (true) {
//read message from Client
String msg = br.readLine();
System.out.println("Client :-"+msg);
if(msg.equals("bye"))
{
break;
}
System.out.println("Enter the message");
String str = ir.readLine();//read the message
//send message
pr.println(str);
if(str.equals("bye"))
{
break;
}
}
//Closing The Connection
System.out.println("Clossing Connection");
s.close();
}
}