private void initSocket(String host, String port) throws IOException { // check the validity of the host name if (host == null || host.isEmpty()) { throw new IllegalArgumentException("host == null || host.isEmpty()"); } // check the validity of the port number int p = 0; try { p = Integer.parseInt(port); } catch (NumberFormatException e) { throw new IllegalArgumentException("Illegal port argument"); } if (p <= 0) { throw new IllegalArgumentException("Illegal port argument"); } // establish the network connection try { this.socket = new Socket(host, p); } catch (IOException e) { getErrorManager().error("Failed to establish the network connection", e, ErrorManager.OPEN_FAILURE); throw e; } super.internalSetOutputStream(new BufferedOutputStream(this.socket.getOutputStream())); }
/** * Constructs a {@code SocketHandler} object using the specified host name * and port number together with other properties read by the log manager. * Default formatting uses the XMLFormatter class and level is set to ALL. * * @param host * the host name * @param port * the port number * @throws IOException * if failed to connect to the specified host and port. * @throws IllegalArgumentException * if the host name or port number is illegal. */ public SocketHandler(String host, int port) throws IOException { super(DEFAULT_LEVEL, null, DEFAULT_FORMATTER, null); initSocket(host, String.valueOf(port)); }
handler = new SocketHandler(host, port); handler.setLevel(toSetLevel); if (formatter != null) handler.setFormatter(formatter); if (filter != null) handler.setFilter(filter); this.handlers.get(loggerName).put(handlerName, handler); } else { handler.close();
while (true) { // Accept a connection Socket socket = servSock.accept(); // Spin off a thread to deal with the client connection new SocketHandler(socket).start(); }
for (;;) { SocketHandler socketHander = new SocketHandler(serverSocket.accept()); socketHander.start(); }
/** * Closes this handler. The network connection to the host is also closed. */ @Override public void close() { try { super.close(); if (this.socket != null) { this.socket.close(); this.socket = null; } } catch (Exception e) { getErrorManager().error("Exception occurred when closing the socket handler", e, ErrorManager.CLOSE_FAILURE); } }
/** * Constructs a {@code SocketHandler} object using the properties read by * the log manager, including the host name and port number. Default * formatting uses the XMLFormatter class and level is set to ALL. * * @throws IOException * if failed to connect to the specified host and port. * @throws IllegalArgumentException * if the host name or port number is illegal. */ public SocketHandler() throws IOException { super(DEFAULT_LEVEL, null, DEFAULT_FORMATTER, null); initSocket(LogManager.getLogManager().getProperty( "java.util.logging.SocketHandler.host"), LogManager .getLogManager().getProperty( "java.util.logging.SocketHandler.port")); }
Thread socketT = new Thread(new SocketHandler(socket));
@Override public void close() { try { super.close(); if (this.socket != null) { this.socket.close(); this.socket = null; } } catch (Exception e) { getErrorManager().error("Exception occurred when closing the socket handler", e, ErrorManager.CLOSE_FAILURE); } }
public SocketHandler(String host, int port) throws IOException { super(DEFAULT_LEVEL, null, DEFAULT_FORMATTER, null); initSocket(host, String.valueOf(port)); }
server = new ServerSocket(port); while (continueAccpetingConnections) { Socket socket = server.accept(); Thread thread = new Thread(new SocketHandler(socket)); thread.start(); }
private void initSocket(String host, String port) throws IOException { // check the validity of the host name if (host == null || host.isEmpty()) { throw new IllegalArgumentException("host == null || host.isEmpty()"); } // check the validity of the port number int p = 0; try { p = Integer.parseInt(port); } catch (NumberFormatException e) { throw new IllegalArgumentException("Illegal port argument"); } if (p <= 0) { throw new IllegalArgumentException("Illegal port argument"); } // establish the network connection try { this.socket = new Socket(host, p); } catch (IOException e) { getErrorManager().error("Failed to establish the network connection", e, ErrorManager.OPEN_FAILURE); throw e; } super.internalSetOutputStream(new BufferedOutputStream(this.socket.getOutputStream())); }
/** * Constructs a {@code SocketHandler} object using the specified host name * and port number together with other properties read by the log manager. * Default formatting uses the XMLFormatter class and level is set to ALL. * * @param host * the host name * @param port * the port number * @throws IOException * if failed to connect to the specified host and port. * @throws IllegalArgumentException * if the host name or port number is illegal. */ public SocketHandler(String host, int port) throws IOException { super(DEFAULT_LEVEL, null, DEFAULT_FORMATTER, null); initSocket(host, String.valueOf(port)); }
threadHandler = new ThreadPoolExecutor( maxThreads, maxThreads, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>( maxThreads, true ) ); while (!serverTerminated) { try { final Socket connectionSocket = serversocket.accept(); SocketHandler handler = new SocketHandler( this, connectionSocket ); threadHandler.submit( handler ); } catch (IOException e) { if (!serverTerminated) e.printStackTrace(); } }
private void initSocket(String host, String port) throws IOException { // check the validity of the host name if (host == null || host.isEmpty()) { throw new IllegalArgumentException("host == null || host.isEmpty()"); } // check the validity of the port number int p = 0; try { p = Integer.parseInt(port); } catch (NumberFormatException e) { throw new IllegalArgumentException("Illegal port argument"); } if (p <= 0) { throw new IllegalArgumentException("Illegal port argument"); } // establish the network connection try { this.socket = new Socket(host, p); } catch (IOException e) { getErrorManager().error("Failed to establish the network connection", e, ErrorManager.OPEN_FAILURE); throw e; } super.internalSetOutputStream(new BufferedOutputStream(this.socket.getOutputStream())); }
/** * Constructs a {@code SocketHandler} object using the specified host name * and port number together with other properties read by the log manager. * Default formatting uses the XMLFormatter class and level is set to ALL. * * @param host * the host name * @param port * the port number * @throws IOException * if failed to connect to the specified host and port. * @throws IllegalArgumentException * if the host name or port number is illegal. */ public SocketHandler(String host, int port) throws IOException { super(DEFAULT_LEVEL, null, DEFAULT_FORMATTER, null); initSocket(host, String.valueOf(port)); }
ServerSocket ss = new ServerSocket(KNOWN_PORT); while(running) { executor.submit(new SocketHandler(ss.accept()));
private void initSocket(String host, String port) throws IOException { // check the validity of the host name if (host == null || host.isEmpty()) throw new IllegalArgumentException("host == null || host.isEmpty()"); // check the validity of the port number int p = 0; try { p = Integer.parseInt(port); } catch (NumberFormatException e) { throw new IllegalArgumentException("Illegal port argument"); } if (p <= 0) { throw new IllegalArgumentException("Illegal port argument"); } // establish the network connection try { this.socket = new Socket(host, p); } catch (IOException e) { getErrorManager().error("Failed to establish the network connection", e, ErrorManager.OPEN_FAILURE); throw e; } super.internalSetOutputStream(new BufferedOutputStream(this.socket.getOutputStream())); }
/** * Constructs a {@code SocketHandler} object using the specified host name * and port number together with other properties read by the log manager. * Default formatting uses the XMLFormatter class and level is set to ALL. * * @param host * the host name * @param port * the port number * @throws IOException * if failed to connect to the specified host and port. * @throws IllegalArgumentException * if the host name or port number is illegal. */ public SocketHandler(String host, int port) throws IOException { super(DEFAULT_LEVEL, null, DEFAULT_FORMATTER, null); initSocket(host, String.valueOf(port)); }
ServerSocket ss = new ServerSocket(... params ...); while(isRunning) { Socket socket = ss.accept(); Runnable r = new SocketHandler(socket); // write the socket handler class Thread t = new Thread(r); t.start(); }