source: trunk/src/org/expeditee/network/DefaultServer.java@ 838

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

Implement automatically downloading images from FrameShare servers. Also includes code for uploading images, but that's not ready yet.

File size: 1.5 KB
Line 
1package org.expeditee.network;
2
3import java.io.IOException;
4import java.net.DatagramSocket;
5
6public abstract class DefaultServer extends Thread {
7
8
9 protected static final int MAX_PACKET_LENGTH = 64000;
10 protected static final int FRAMENAME_PACKET_LENGTH = 1000;
11
12 protected boolean _stop = false;
13 protected DatagramSocket socket = null;
14
15 public DefaultServer() {
16 super();
17 }
18
19 public DefaultServer(Runnable target) {
20 super(target);
21 }
22
23 protected DefaultServer(String name) {
24 super(name);
25 }
26
27 public DefaultServer(String name, int port) throws IOException {
28 super(name);
29 socket = new DatagramSocket(port);
30 }
31
32 public DefaultServer(ThreadGroup group, Runnable target) {
33 super(group, target);
34 }
35
36 public DefaultServer(ThreadGroup group, String name) {
37 super(group, name);
38 }
39
40 public DefaultServer(Runnable target, String name) {
41 super(target, name);
42 }
43
44 public DefaultServer(ThreadGroup group, Runnable target, String name) {
45 super(group, target, name);
46 }
47
48 public DefaultServer(ThreadGroup group, Runnable target, String name,
49 long stackSize) {
50 super(group, target, name, stackSize);
51 }
52
53 public void close() {
54 _stop = true;
55 }
56
57 public void run() {
58 //MessageBay.displayMessage(this.getName() + " started on port "
59 // + socket.getLocalPort());
60
61 while (!_stop) {
62 try {
63 listenForMessages();
64
65 } catch (IOException e) {
66 e.printStackTrace();
67 }
68 }
69 socket.close();
70 }
71
72 protected abstract void listenForMessages() throws IOException;
73
74}
Note: See TracBrowser for help on using the repository browser.