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

Last change on this file since 649 was 649, checked in by davidb, 10 years ago

Code added so command-line version of FrameShare starts the thread for the server(s)

File size: 1.4 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 private 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 public DefaultServer(String name, int port) throws IOException {
24 super(name);
25 socket = new DatagramSocket(port);
26 }
27
28 public DefaultServer(ThreadGroup group, Runnable target) {
29 super(group, target);
30 }
31
32 public DefaultServer(ThreadGroup group, String name) {
33 super(group, name);
34 }
35
36 public DefaultServer(Runnable target, String name) {
37 super(target, name);
38 }
39
40 public DefaultServer(ThreadGroup group, Runnable target, String name) {
41 super(group, target, name);
42 }
43
44 public DefaultServer(ThreadGroup group, Runnable target, String name,
45 long stackSize) {
46 super(group, target, name, stackSize);
47 }
48
49 public void close() {
50 _stop = true;
51 }
52
53 public void run() {
54 //MessageBay.displayMessage(this.getName() + " started on port "
55 // + socket.getLocalPort());
56
57 while (!_stop) {
58 try {
59 listenForMessages();
60
61 } catch (IOException e) {
62 e.printStackTrace();
63 }
64 }
65 socket.close();
66 }
67
68 protected abstract void listenForMessages() throws IOException;
69
70}
Note: See TracBrowser for help on using the repository browser.