-
Notifications
You must be signed in to change notification settings - Fork 1
/
Server.java
47 lines (40 loc) · 1.1 KB
/
Server.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
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
ServerSocket ss;
Socket s;
DataInputStream dis;
DataOutputStream dos;
public Server() {
try{
System.out.println("SERVER STARTED");
ss=new ServerSocket(100);
s=ss.accept();
System.out.println(s);
System.out.println("CLIENT CONNECTED");
dis=new DataInputStream(s.getInputStream());
dos=new DataOutputStream(s.getOutputStream());
serverchat();
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String args[]) {
new Server();
}
public void serverchat() throws IOException {
String str;
do {
str=dis.readUTF();
System.out.println("client message "+str);
dos.writeUTF("hello "+ str);
dos.flush();
}
while(!str.equals("stop"));
}
}