6c486241147c0b294375925df2b7439903d233cf
[WeStealzYourDataz.git] / src / uk / ac / ntu / n0521366 / wsyd / libs / net / NetworkServerTCP.java
1 /*
2  * The MIT License
3  *
4  * Copyright 2015 TJ <hacker@iam.tj>.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 package uk.ac.ntu.n0521366.wsyd.libs.net;
25
26 import java.net.ServerSocket;
27 import java.net.SocketException;
28
29 /**
30  * Dual-use multithreading network TCP server that can be used stand-alone
31  * or in a Swing GUI application as a background worker thread.
32  *
33  * @see NetworkServerAbstract
34  * @author TJ <hacker@iam.tj>
35  */
36 public class NetworkServerTCP extends NetworkServerAbstract {
37     ServerSocket _serverSocket;
38
39     /**
40      * Open the socket ready for accepting connections.
41      * 
42      * It should also set a reasonable socket timeout with a call to setSoTimeout()
43      * 
44      * @throws SocketException 
45      */
46     @Override
47     public  void serverOpen() throws SocketException {
48         
49     }
50     
51     /**
52      * Send an unsolicited message to a remote service.
53      * 
54      * This method is called by the main worker loop if there is a message to
55      * be sent.
56      * 
57      * @param message must have its _serviceTarget parameter set
58      * @return true if the message was sent
59      */
60     @Override
61     protected boolean serverSend(NetworkMessage message) {
62         boolean result = false;
63         
64         return result;
65     }
66
67     /**
68      * Close the socket.
69      * 
70      * @throws SocketException
71      */
72     @Override
73     public void serverClose() throws SocketException {
74         
75     }
76     
77     /**
78      * Accept connection from remote hosts.
79      * 
80      * This method should wait for a single incoming connection.
81      * 
82      * @return true if the server should continue listening
83      */
84     @Override
85     public boolean serverListen() {
86         boolean result = false;
87         
88         return false;
89     }
90
91     /* XXX: Methods below here all execute on the GUI Event Dispatch Thread */
92     
93     /**
94      * Clean up after doInBackground() has returned.
95      * 
96      * This method will run on the GUI Event Dispatch Thread so must complete quickly.
97      */
98     @Override
99     protected  void done() {
100         
101     }
102 }