-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriter.java
More file actions
43 lines (40 loc) · 1.29 KB
/
Copy pathWriter.java
File metadata and controls
43 lines (40 loc) · 1.29 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
import java.net.Socket;
import java.util.Random;
import java.io.IOException;
import java.io.ObjectOutputStream;;
public class Writer implements Runnable {
private Socket socket;
private Model model;
private int clientID;
public Packet packet;
/**
* Constructor for Writer that takes the static packet and model variables from the server
* Also takes the socket for the client and assigned clientID
*/
public Writer(Socket s, int clientID, Model model, Packet packet) {
this.socket = s;
this.packet = packet;
this.clientID = clientID;
this.model = model;
}
public void run() {
try {
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
while(true){
/**
* Sends packet containing Client ID and Model every 150ms
*/
packet.setID(this.clientID);
oos.writeObject(packet);
System.out.println("Sending gamestate packet..");
oos.flush();
oos.reset();
Thread.sleep(200);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}