public static boolean treatAsBindException(SocketException se) { if (se instanceof BindException) { return true; } final String msg = se.getMessage(); return (msg != null && msg.contains("Invalid argument: listen failed")); }
public static boolean treatAsBindException(SocketException se) { if (se instanceof BindException) { return true; } final String msg = se.getMessage(); return (msg != null && msg.contains("Invalid argument: listen failed")); }
private void acceptConnections() throws Exception { while (true) { Socket socket; try { socket = serverSocket.accept(); } catch (SocketException e) { logger.info(MockWebServer.this + " done accepting connections: " + e.getMessage()); return; } SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy(); if (socketPolicy == DISCONNECT_AT_START) { dispatchBookkeepingRequest(0, socket); socket.close(); } else { openClientSockets.add(socket); serveConnection(socket); } } } });
private boolean initializeSocket(int port) { log.info("Initializing UDP response Socket..."); udpResponsePort = port; boolean portLoopControl = true; int retryCount = 0; while(portLoopControl) { try { responseSocket = new DatagramSocket(udpResponsePort); portLoopControl = false; } catch(SocketException e) { if(retryCount == 0) log.warn("UDP Response Port is in use, starting loop to find open port for 20 tries - configured port is: " + udpResponsePort); if(retryCount >= 20) { portLoopControl = false; log.error("UDP Response Port issue, could not find open port - last port tried: " + udpResponsePort + " with message: " + e.getMessage()); return false; } } if(portLoopControl) { retryCount++; udpResponsePort++; } } log.info("UDP response Socket initialized to: " + udpResponsePort); return true; }
AnnotatedSocketException(SocketException exception, SocketAddress remoteAddress) { super(exception.getMessage() + ": " + remoteAddress); initCause(exception); setStackTrace(exception.getStackTrace()); }
@Override void dump( Logger logger ) { try { Enumeration<NetworkInterface> networkInterfaces = getNetworkInterfaces(); while ( networkInterfaces.hasMoreElements() ) { NetworkInterface iface = networkInterfaces.nextElement(); logger.log( String.format( "Interface %s:", iface.getDisplayName() ) ); Enumeration<InetAddress> addresses = iface.getInetAddresses(); while ( addresses.hasMoreElements() ) { InetAddress address = addresses.nextElement(); String hostAddress = address.getHostAddress(); logger.log( " address: %s", hostAddress ); } } } catch ( SocketException e ) { logger.log( "ERROR: failed to inspect network interfaces and addresses: " + e.getMessage() ); } } },
AnnotatedSocketException(SocketException exception, SocketAddress remoteAddress) { super(exception.getMessage() + ": " + remoteAddress); initCause(exception); setStackTrace(exception.getStackTrace()); }
ifs = NetworkInterface.getNetworkInterfaces(); } catch(SocketException e) { log.error("checkIpAddress cannot get ip address of this host, Exiting with message: " + e.getMessage(), e); return null;
/** * A convenience method to bind to a given address and report * better exceptions if the address is not a valid host. * @param socket the socket to bind * @param address the address to bind to * @param backlog the number of connections allowed in the queue * @throws BindException if the address can't be bound * @throws UnknownHostException if the address isn't a valid host name * @throws IOException other random errors from bind */ public static void bind(ServerSocket socket, InetSocketAddress address, int backlog) throws IOException { try { socket.bind(address, backlog); } catch (BindException e) { BindException bindException = new BindException("Problem binding to " + address + " : " + e.getMessage()); bindException.initCause(e); throw bindException; } catch (SocketException e) { // If they try to bind to a different host's address, give a better // error message. if ("Unresolved address".equals(e.getMessage())) { throw new UnknownHostException("Invalid hostname for server: " + address.getHostName()); } throw e; } }
AnnotatedSocketException(SocketException exception, SocketAddress remoteAddress) { super(exception.getMessage() + ": " + remoteAddress); initCause(exception); setStackTrace(exception.getStackTrace()); }
public ClusterManager() { try { zeplServerHost = RemoteInterpreterUtils.findAvailableHostAddress(); String clusterAddr = zconf.getClusterAddress(); if (!StringUtils.isEmpty(clusterAddr)) { String cluster[] = clusterAddr.split(","); for (int i = 0; i < cluster.length; i++) { String[] parts = cluster[i].split(":"); String clusterHost = parts[0]; int clusterPort = Integer.valueOf(parts[1]); if (zeplServerHost.equalsIgnoreCase(clusterHost)) { raftServerPort = clusterPort; } Node node = Node.builder().withId(cluster[i]) .withAddress(Address.from(clusterHost, clusterPort)).build(); clusterNodes.add(node); raftAddressMap.put(MemberId.from(cluster[i]), Address.from(clusterHost, clusterPort)); clusterMemberIds.add(MemberId.from(cluster[i])); } } } catch (UnknownHostException e) { LOGGER.error(e.getMessage()); } catch (SocketException e) { LOGGER.error(e.getMessage()); } }
private void init() { ServerSocketChannel socketChannel = processor.javaChannel(); ServerSocket javaSocket = socketChannel.socket(); try { if (serverConfig.getReceiveBufferSize() != null) { javaSocket.setReceiveBufferSize(serverConfig.getReceiveBufferSize()); } if (serverConfig.getReuseAddress() != null) { javaSocket.setReuseAddress(serverConfig.getReuseAddress()); } } catch (SocketException e) { throw new NioException("config channel error:" + e.getMessage(), e); } }
private void init() { ServerSocketChannel socketChannel = processor.javaChannel(); ServerSocket javaSocket = socketChannel.socket(); try { if (serverConfig.getReceiveBufferSize() != null) { javaSocket.setReceiveBufferSize(serverConfig.getReceiveBufferSize()); } if (serverConfig.getReuseAddress() != null) { javaSocket.setReuseAddress(serverConfig.getReuseAddress()); } } catch (SocketException e) { throw new NioException("config channel error:" + e.getMessage(), e); } }
if (!e.getMessage().toLowerCase(Locale.US).contains("socket closed")) { throw e;
@Override void handleClientSocket(Socket clientSocket) throws IOException { LOG.info("Writing to client"); BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); PrintWriter out = new PrintWriter(clientSocket.getOutputStream()); try { out.println("Hello"); out.flush(); String line = in.readLine(); while (line != null && isServerRunning()) { out.println(line + " " + line); out.flush(); line = in.readLine(); } } catch (SocketException se) { // don't bring down server when client disconnected abruptly if (!se.getMessage().contains("Connection reset")) { throw se; } } finally { clientSocket.close(); } } }
LOG.warn("Interrupted", e); } catch (SocketException e) { if (!"Socket closed".equals(e.getMessage())) { LOG.error("Unexpected exception", e);
if (!e.getMessage().toLowerCase(Locale.US).contains("socket closed")) { throw e;
if (!e.getMessage().toLowerCase(Locale.US).contains("socket closed")) { throw e;
/** * Checks whether we are effected by the JDK issue on windows, and if so * ensures that we are running with preferIPv4Stack=true. */ @Test public void testServerSocket() throws IOException { byte[] addr = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; InetAddress inetAddr = InetAddress.getByAddress(addr); try { bindServerSocket(inetAddr); bindNIOServerSocket(inetAddr); //if on *nix or windows JDK7, both will pass } catch(java.net.SocketException ex) { //On Windows JDK6, we will get expected exception: //java.net.SocketException: Address family not supported by protocol family //or java.net.SocketException: Protocol family not supported Assert.assertFalse(ex instanceof BindException); Assert.assertTrue(ex.getMessage().toLowerCase(Locale.ROOT).contains("protocol family")); LOG.info("Received expected exception:", ex); //if this is the case, ensure that we are running on preferIPv4=true ensurePreferIPv4(); } }
LOG.warn("Couldn't find loopback interface: " + se.getMessage());