Server thread implementation.
242 Registry conf = Registry.getCurrent();
243 Enumeration keys = conf.getSectionKeys(
"server");
245 throw new Exception(
"No server configuration found");
249 listener.setReuseAddress(
true);
252 InetSocketAddress iface = null;
253 while (keys.hasMoreElements()) {
254 String key = (String) keys.nextElement();
256 iface = (InetSocketAddress) conf.get(
"server", key);
257 listener.bind(iface);
259 InetAddress addr = iface.getAddress();
260 String msg =
"Accepting connections @";
261 msg += addr.getHostAddress() +
":" + iface.getPort();
263 if (addr.isAnyLocalAddress())
264 msg +=
" (all local)";
266 else if (addr.isMulticastAddress())
267 msg +=
" (multicast)";
270 msg +=
" (" + addr.getCanonicalHostName() +
")";
272 log.appendln(msg,
"status");
275 if (iface == null || !
listener.isBound())
276 throw new Exception(
"No server configuration found");
278 firePropertyChange(
"isServing", null,
true);
279 status.startUptimeTimer();
282 while (
server == Thread.currentThread()) {
283 status.setMessage(
"Waiting for connections",
true);
286 Socket peer = listener.accept();
288 String addr = peer.getInetAddress().getHostAddress();
289 int port = peer.getPort();
290 log.appendln(
"Connected peer @" + addr +
":" + port,
"status");
292 desktop.register(peer);
295 catch (Throwable t) {
296 log.appendln(t.toString(),
"alert");
297 if (!(t instanceof IOException))
302 status.stopUptimeTimer();
303 status.setMessage(
"Service complete",
true);
304 firePropertyChange(
"isServing", null,
false);
307 catch (Throwable t) {
312 log.appendln(
"Failed to start server (" + t.toString() +
")",
"error");
313 status.setMessage(
"Server failed",
false);
Thread server
Server thread.
void shutdown()
Close the listening server socket and shutdown the server.
ServerSocket listener
Listener socket.