source: trunk/src/org/expeditee/network/InfUpdate.java@ 309

Last change on this file since 309 was 308, checked in by ra33, 16 years ago

Servers for returning the number for the next frame in remote framesets

File size: 1.3 KB
Line 
1package org.expeditee.network;
2
3import java.io.IOException;
4import java.net.DatagramPacket;
5import java.net.InetAddress;
6
7import org.expeditee.gui.FrameIO;
8import org.expeditee.gui.MessageBay;
9
10public 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}
Note: See TracBrowser for help on using the repository browser.