1 /*********************************************************************
5 * Purpose : Listen on a specified port for status updates from
6 * Privoxy. If we get a suitable update, pass it along
7 * to the GUI for processing. We need to handle getting
8 * shut down and restarting on another port gracefully.
10 * Copyright : Written by and Copyright (C) 2003 the SourceForge
11 * Privoxy team. http://www.privoxy.org/
13 * Based on the Internet Junkbuster originally written
14 * by and Copyright (C) 1997 Anonymous Coders and
15 * Junkbusters Corporation. http://www.junkbusters.com
17 * This program is free software; you can redistribute it
18 * and/or modify it under the terms of the GNU General
19 * Public License as published by the Free Software
20 * Foundation; either version 2 of the License, or (at
21 * your option) any later version.
23 * This program is distributed in the hope that it will
24 * be useful, but WITHOUT ANY WARRANTY; without even the
25 * implied warranty of MERCHANTABILITY or FITNESS FOR A
26 * PARTICULAR PURPOSE. See the GNU General Public
27 * License for more details.
29 * The GNU General Public License should be included with
30 * this file. If not, you can view it at
31 * http://www.gnu.org/copyleft/gpl.html
32 * or write to the Free Software Foundation, Inc., 59
33 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 *********************************************************************/
39 package org.privoxy.activityconsole;
48 * Listens on a specified port for status updates from Privoxy.
49 * @author Last Modified By: $Author$
50 * @version $Rev$-$Date$$State$
52 public class ServerThread extends Thread
54 private static final String
55 COPYRIGHT = org.privoxy.activityconsole.Copyright.COPYRIGHT;
57 static ActivityConsoleGui _parent;
59 static ServerSocket _serverSocket;
61 public ServerThread(ActivityConsoleGui parent, int thePort)
71 _serverSocket = new ServerSocket(_port);
74 // System.out.println( "ServerThread serving port "+_port+"." );
75 boolean shouldRun = true;
78 Socket theSocket = _serverSocket.accept();
79 if (!Thread.currentThread().interrupted())
82 new BufferedReader(new InputStreamReader(theSocket.getInputStream()));
83 String line = in.readLine();
84 /* Ensure the line isn't null and it's not way, way too long... */
85 if ((line != null) && (line.length() < 65536))
87 _parent.updateStats(line,theSocket.getInetAddress().getHostName());
97 _serverSocket.close();
100 catch (IOException io)
104 _serverSocket.close();
105 _serverSocket = null;
107 catch (IOException fred)
109 _serverSocket = null;
113 catch (IOException io)
115 System.err.println(io);
116 JOptionPane.showMessageDialog(null, io, "Alert: port "+_port, JOptionPane.ERROR_MESSAGE);
120 public void doClose()
124 _serverSocket.close();
126 catch (IOException fred)