1 | package org.expeditee.network;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import java.net.DatagramPacket;
|
---|
5 | import java.net.InetAddress;
|
---|
6 |
|
---|
7 | import org.expeditee.gui.FrameIO;
|
---|
8 | import org.expeditee.gui.MessageBay;
|
---|
9 |
|
---|
10 | public class InfUpdate extends DefaultServer {
|
---|
11 | public final static int OFFSET = 4;
|
---|
12 |
|
---|
13 | public InfUpdate(int port) throws IOException {
|
---|
14 | super("InfUpdate", port + OFFSET);
|
---|
15 | }
|
---|
16 |
|
---|
17 | @Override
|
---|
18 | protected void listenForMessages() throws IOException {
|
---|
19 | byte[] buf = new byte[FRAMENAME_PACKET_LENGTH];
|
---|
20 |
|
---|
21 | // receive request
|
---|
22 | DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
---|
23 | socket.receive(packet);
|
---|
24 |
|
---|
25 | String framesetName = new String(packet.getData(), 0, packet
|
---|
26 | .getLength());
|
---|
27 | MessageBay.displayMessage("Recieved inf update request for " + framesetName);
|
---|
28 |
|
---|
29 | // figure out response
|
---|
30 | int next = FrameIO.ReadINF(FrameIO.PUBLIC_PATH, framesetName, true);
|
---|
31 | FrameIO.WriteINF(FrameIO.PUBLIC_PATH, framesetName, framesetName
|
---|
32 | + (next + 1));
|
---|
33 | String dString = next + "";
|
---|
34 |
|
---|
35 | if (dString != null && dString.length() > 0) {
|
---|
36 | buf = dString.getBytes();
|
---|
37 |
|
---|
38 | // send the response to the client at "address" and "port"
|
---|
39 | InetAddress address = packet.getAddress();
|
---|
40 | int port = packet.getPort();
|
---|
41 | packet = new DatagramPacket(buf, buf.length, address, port);
|
---|
42 | socket.send(packet);
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|