/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This is the base class for network servers. To define a new type
* of server define a new subclass of NetworkServer with a serviceRequest
* method that services one request. Start the server by executing:
* <pre>
* new MyServerClass().startServer(port);
* </pre>
*/
/** Socket for communicating with client. */
/** Stream for printing to the client. */
/** Buffered stream for reading replies from client. */
/** Close an open connection to the client. */
clientSocket = null;
clientInput = null;
clientOutput = null;
}
/** Return client connection status */
public boolean clientIsOpen() {
return clientSocket != null;
}
final public void run() {
if (serverSocket != null) {
// System.out.print("Server starts " + serverSocket + "\n");
while (true) {
try {
// System.out.print("New connection " + ns + "\n");
n.serverSocket = null;
n.clientSocket = ns;
} catch(Exception e) {
e.printStackTrace();
try {
} catch(IOException e2) {}
break;
}
}
// close();
} else {
try {
clientOutput = new PrintStream(
false, "ISO8859_1");
// System.out.print("Service handler exits
// "+clientSocket+"\n");
} catch(Exception e) {
// System.out.print("Service handler failure\n");
// e.printStackTrace();
}
try {
close();
} catch(IOException e2) {}
}
}
/** Start a server on port <i>port</i>. It will call serviceRequest()
for each new connection. */
serverInstance = new Thread(this);
}
/** Service one request. It is invoked with the clientInput and
clientOutput streams initialized. This method handles one client
connection. When it is done, it can simply exit. The default
server just echoes it's input. It is invoked in it's own private
thread. */
byte buf[] = new byte[300];
int n;
}
}
try {
} catch (IOException e) {
}
}
/**
* Clone this object;
*/
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
public NetworkServer () {
}
}