-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
57 lines (37 loc) · 1.02 KB
/
Server.java
File metadata and controls
57 lines (37 loc) · 1.02 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
45
46
47
48
49
50
51
52
53
54
55
56
57
package cop2805;
import java.io.IOException;
import java.net.*;
import java.io.*;
public class Server {
public static String decrypt(String input) {
String result = "";
for(int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
c = (char)(c + 10);
result = result + c;
}
return result;
}
public static void main(String[] args) {
boolean shutdown = false;
try {
ServerSocket server = new ServerSocket(1234);
while (!shutdown) {
Socket client = server.accept();
BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
String input = br.readLine();
String decrypted = decrypt(input);
if(input.contains("shutdown")) {
shutdown = true;
}
PrintWriter pr = new PrintWriter(new OutputStreamWriter(client.getOutputStream()));
pr.println(decrypted);
pr.flush();
client.close();
}
server.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}