source: trunk/src/org/expeditee/network/InfServer.java@ 1510

Last change on this file since 1510 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 1.9 KB
Line 
1/**
2 * InfServer.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.network;
20
21import java.io.IOException;
22import java.net.DatagramPacket;
23import java.net.InetAddress;
24
25import org.expeditee.gui.FrameIO;
26import org.expeditee.gui.MessageBay;
27
28public class InfServer extends DefaultServer {
29 public final static int OFFSET = 3;
30
31 public InfServer(int port) throws IOException {
32 super("InfServer", port + OFFSET);
33 }
34
35 @Override
36 protected void listenForMessages() throws IOException {
37 byte[] buf = new byte[FRAMENAME_PACKET_LENGTH];
38
39 // receive request
40 DatagramPacket packet = new DatagramPacket(buf, buf.length);
41 socket.receive(packet);
42
43 String framesetName = new String(packet.getData(), 0, packet
44 .getLength());
45 MessageBay.displayMessage("Recieved inf request for " + framesetName);
46
47 // figure out response
48 int next = FrameIO.ReadINF(FrameIO.PUBLIC_PATH, framesetName, false);
49 String dString = next + "";
50
51 if (dString != null && dString.length() > 0) {
52 buf = dString.getBytes();
53
54 // send the response to the client at "address" and "port"
55 InetAddress address = packet.getAddress();
56 int port = packet.getPort();
57 packet = new DatagramPacket(buf, buf.length, address, port);
58 socket.send(packet);
59 }
60 }
61}
Note: See TracBrowser for help on using the repository browser.