-
Notifications
You must be signed in to change notification settings - Fork 1
/
ServerTCPNotSecure.java
48 lines (38 loc) · 1.34 KB
/
ServerTCPNotSecure.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
import java.net.ServerSocket;
import java.net.Socket;
public class ServerTCPNotSecure extends ServerTCP {
private int port = 1027;
private ServerSocket server = null;
private Socket client = null;
private int clientCount = 0;
public ServerTCPNotSecure() {}
public ServerTCPNotSecure(int port) {
this.port = port;
}
public int getClientCount() {
return clientCount;
}
public void setClientCount(int clientCount) {
this.clientCount = clientCount;
}
/* this is not secure version */
public void startServer() {
System.out.println(">> start running none encyrted tcp server.");
try {
server = new ServerSocket(this.port);
System.out.println("## Server start listening on port (" + this.port + ")");
while (true) {
client = server.accept();
clientCount++;
ServerThread serverThread = new ServerThread(client, clientCount, this);
serverThread.start();
}
} catch (Exception e) {
System.err.println("Error in startServer() : " + e.getMessage());
}
}
// public static void main(String[] args) throws IOException {
// ServerTCPNotSecure serverobj = new ServerTCPNotSecure(1027);
// serverobj.startServer();
// }
}