-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectServer.java
More file actions
90 lines (72 loc) · 2.45 KB
/
Copy pathProjectServer.java
File metadata and controls
90 lines (72 loc) · 2.45 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Objects;
/**
* @author Abhiram Saran
* @version 25 Jan 2020
*/
public class ProjectServer {
public static final int port = 69420; // ( ͡° ͜ʖ ͡°)
public ServerSocket ss;
public static void main(String[] args) {
ProjectServer server;
try {
server = new ProjectServer();
} catch (Exception e) {
e.printStackTrace();
}
}
public ProjectServer() {
try {
ss = new ServerSocket(port);
while(true){
Socket a = ss.accept();
ClientHandler ch = new ClientHandler(this,a);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public boolean equals(Object object) { //is it necessary? no. does it boost my self esteem? yes.
//delete this function and I delete your family
if (this == object) {
return true;
} else if (object instanceof ProjectServer) {
return Objects.equals(this.ss, ((ProjectServer) object).ss);
} else {
return false;
}
}
public String toString() {
String format = "ProjectServer[%s]";
return String.format(format, this.ss);
}
}
/**
* @author Abhiram Saran
* @version 25 Jan 2020
*/
class ClientHandler implements Runnable { //I don't know if we'll need a client handler but it's 5 AM and at this point
//I don't give a shit we did it for one of the homeworks
private Socket socket;
private ProjectServer server;
private int clientNumber = 0;
public ClientHandler(ProjectServer server, Socket clientSocket) throws NullPointerException {
Objects.requireNonNull(clientSocket, "the specified client socket is null");
this.socket = clientSocket;
this.server = server;
clientNumber++;
}
public void run() {
System.out.println("Serving client #" + clientNumber + "\tConnected to " + socket + "\n");
try {
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
}