Code example for ServerSocket

Methods: setReuseAddress

0
        private ServerSocket serverSocket;
        private int port = -1;
 
        MockServer() throws IOException { 
            executor = Executors.newCachedThreadPool();
            serverSocket = new ServerSocket(0);
            serverSocket.setReuseAddress(true);
            port = serverSocket.getLocalPort();
        } 
 
        public Future<byte[]> enqueue(final byte[] sendBytes, final int receiveByteCount)
                throws IOException { 
            return executor.submit(new Callable<byte[]>() {
                @Override public byte[] call() throws Exception { 
                    Socket socket = serverSocket.accept();
                    OutputStream out = socket.getOutputStream();
                    out.write(sendBytes);
 
                    InputStream in = socket.getInputStream();
                    byte[] result = new byte[receiveByteCount];
                    int total = 0;