-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerListenerThread.java
More file actions
55 lines (43 loc) · 1.19 KB
/
ServerListenerThread.java
File metadata and controls
55 lines (43 loc) · 1.19 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
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.HashMap;
public class ServerListenerThread extends Thread {
private Socket socket;
private ObjectInputStream ois;
private HashMap<Integer, Socket> h;
private ObjectOutputStream oos;
public ServerListenerThread(Socket socket, HashMap<Integer, Socket> h) {
this.h = h;
this.socket = socket;
}
public void run() {
try {
while (true)
{
ois = new ObjectInputStream(socket.getInputStream());
Object obj = ois.readObject();
ClientData dataFromClient = null;
if (obj instanceof ClientData) {
ClientData cd= (ClientData) obj;
h.put(new Integer(cd.id), socket);
System.out.println("Server Received: " + cd.id);
Bus.OrderStation((String)cd.dest);
} else if (obj instanceof String) {
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject("Server Reply");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}