forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCP_ChatServer.java
More file actions
44 lines (36 loc) · 1.07 KB
/
TCP_ChatServer.java
File metadata and controls
44 lines (36 loc) · 1.07 KB
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
package netpck;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class TCP_ChatServer {
/**
* @param args
* @throws IOException
* @throws UnknownHostException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
ServerSocket ss = new ServerSocket(1406);
Socket s = ss.accept();
DataInputStream di = new DataInputStream(s.getInputStream());
DataOutputStream ds = new DataOutputStream(s.getOutputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String sin = "" , sout = "" ;
while (!sin.equalsIgnoreCase("bye") && !sin.equalsIgnoreCase("jsk")) {
sin = di.readUTF();
System.out.println("[SERVER] Received Message is : "+sin);
System.out.println("Enter Message : ");
sout = br.readLine();
ds.writeUTF(sout);
ds.flush();
}
di.close();
ds.close();
s.close();
ss.close();
}
}