Java Code Examples for java.net.ServerSocket#isBound()
The following examples show how to use
java.net.ServerSocket#isBound() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GfxdTSSLServerSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Creates a server socket from underlying socket object */ public GfxdTSSLServerSocket(ServerSocket serverSocket, InetSocketAddress bindAddress, SocketParameters params) throws TTransportException { this.socketParams = params; try { this.serverSocket = serverSocket; // Prevent 2MSL delay problem on server restarts serverSocket.setReuseAddress(true); // Bind to listening port if (!serverSocket.isBound()) { // backlog hardcoded to 100 as in TSSLTransportFactory serverSocket.bind(bindAddress, 100); } } catch (IOException ioe) { throw new TTransportException(TTransportException.NOT_OPEN, "Could not bind to host:port " + bindAddress.toString(), ioe); } }
Example 2
Source File: GfxdTSSLServerSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Creates a server socket from underlying socket object */ public GfxdTSSLServerSocket(ServerSocket serverSocket, InetSocketAddress bindAddress, SocketParameters params) throws TTransportException { this.socketParams = params; try { this.serverSocket = serverSocket; // Prevent 2MSL delay problem on server restarts serverSocket.setReuseAddress(true); // Bind to listening port if (!serverSocket.isBound()) { // backlog hardcoded to 100 as in TSSLTransportFactory serverSocket.bind(bindAddress, 100); } } catch (IOException ioe) { throw new TTransportException(TTransportException.NOT_OPEN, "Could not bind to host:port " + bindAddress.toString(), ioe); } }
Example 3
Source File: MockTCPServer.java From fluency with Apache License 2.0 | 5 votes |
private ServerTask( ExecutorService executorService, AtomicLong lastEventTimeStampMilli, EventHandler eventHandler, ServerSocket serverSocket) throws IOException { this.serverExecutorService = executorService; this.lastEventTimeStampMilli = lastEventTimeStampMilli; this.eventHandler = eventHandler; this.serverSocket = serverSocket; if (!serverSocket.isBound()) { serverSocket.bind(null); } }
Example 4
Source File: NetworkServer.java From slide-android with GNU General Public License v2.0 | 4 votes |
@Override public void run() { this.running = true; try { server = new ServerSocket(getPort(), 0); server.setReuseAddress(true); if (!server.isBound()) { server.bind(new InetSocketAddress(getPort())); } if (!server.isClosed()) { client = server.accept(); client.setTcpNoDelay(true); output = new ObjectOutputStream(client.getOutputStream()); output.flush(); } } catch (IOException ioException) { ioException.printStackTrace(); } //connected if (client != null) { final short sensitivity = AppSettings.getInstance().getSystemSettings().getMouseSensitivity(); if (AppSettings.getInstance().getSettingsElements().getPositioningMode() == PositioningMode.ABSOLUTE) { AppSettings.getInstance().getConnectionManager().getNetworkConnectionManager().send( PositioningMode.ABSOLUTE, sensitivity); //, DisplayProperties.getDisplayWidth(), // DisplayProperties.getDisplayHeight()); } else { AppSettings.getInstance().getConnectionManager().getNetworkConnectionManager().send( PositioningMode.RELATIVE, sensitivity); } SettingsActivity.getActivity().startActivity( AppSettings.getInstance().getActivitySettings() .getCanvasIntent()); // Load the Canvas } }
Example 5
Source File: UsbServer.java From slide-android with GNU General Public License v2.0 | 4 votes |
@Override public void run() { this.running = true; try { server = new ServerSocket(getPort()); server.setReuseAddress(true); if (!server.isBound()) { server.bind(new InetSocketAddress(getPort())); } if (!server.isClosed()) { client = server.accept(); client.setTcpNoDelay(true); output = new ObjectOutputStream(client.getOutputStream()); output.flush(); } } catch (IOException e) { e.printStackTrace(); } //connected if (client != null) { final short sensitivity = AppSettings.getInstance().getSystemSettings().getMouseSensitivity(); if (AppSettings.getInstance().getSettingsElements().getPositioningMode() == PositioningMode.ABSOLUTE) { AppSettings.getInstance().getConnectionManager() .getUsbConnectionManager() .send(PositioningMode.ABSOLUTE, sensitivity); } else { AppSettings.getInstance().getConnectionManager().getUsbConnectionManager().send( PositioningMode.RELATIVE, sensitivity); } SettingsActivity.getActivity().startActivity( AppSettings.getInstance().getActivitySettings() .getCanvasIntent()); // Load the Canvas } }
Example 6
Source File: SocketRepository.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private ServerSocket createServerSocket( int port ) throws IOException { ServerSocket serverSocket = new ServerSocket(); serverSocket.setPerformancePreferences( 1, 2, 3 ); // order of importance: bandwidth, latency, connection time serverSocket.setReuseAddress( true ); // It happens in high-paced environments where lots of sockets are opened and closed that the operating // system keeps a lock on a socket. Because of this we have to wait at least for one minute and on some platforms // up to 2 minutes. // Let's take 5 to make sure we can get a socket connection and we still get into trouble. // // mc: It sucks and blows at the same time that we have to do this but I couldn't find another solution. // try { serverSocket.bind( new InetSocketAddress( port ) ); } catch ( BindException e ) { long totalWait = 0L; long startTime = System.currentTimeMillis(); IOException ioException = null; log.logMinimal( "Carte socket repository : Starting a retry loop to bind the server socket on port " + port + ". We retry for 5 minutes until the socket clears in your operating system." ); while ( !serverSocket.isBound() && totalWait < 300000 ) { try { totalWait = System.currentTimeMillis() - startTime; log.logMinimal( "Carte socket repository : Retry binding the server socket on port " + port + " after a " + ( totalWait / 1000 ) + " seconds wait..." ); Thread.sleep( 10000 ); // wait 10 seconds, try again... serverSocket.bind( new InetSocketAddress( port ), 100 ); } catch ( IOException ioe ) { ioException = ioe; } catch ( Exception ex ) { serverSocket.close(); throw new IOException( ex.getMessage() ); } totalWait = System.currentTimeMillis() - startTime; } if ( !serverSocket.isBound() ) { serverSocket.close(); throw ioException; } log.logDetailed( "Carte socket repository : Succesfully bound the server socket on port " + port + " after " + ( totalWait / 1000 ) + " seconds." ); } return serverSocket; }