public void run() {
            Thread.currentThread().setName("FeedbackThread");
            try {
                feedbackSocket = (SSLServerSocket)sslFactory.createServerSocket(feedbackPort);
                feedbackSocket.setNeedClientAuth(true);
            } catch (IOException e) {
                e.printStackTrace();
                messages.release();
                throw new RuntimeException(e);
            }

            effectiveFeedbackPort = feedbackSocket.getLocalPort();
            try {
                // Listen for connections
                startUp.release();
                Socket socket = feedbackSocket.accept();
                // Work around JVM deadlock ... https://community.oracle.com/message/10989561#10989561
                socket.setSoLinger(true, 1);

                // Create streams to securely send and receive data to the client
                InputStream in = socket.getInputStream();
                OutputStream out = socket.getOutputStream();

                waitBeforeSend();
                // Read from in and write to out...
                toSend.writeTo(out);

                // Close the socket
                in.close();
                out.close();
            } catch (SocketException se) {
                // Ignore closed socket.
            } catch (IOException ioex) {
                ioex.printStackTrace();
            }
            messages.release();
        }
Create an ApnsServerStub that uses any free port for gateway and feedback.

@return the server stub. Use getEffectiveGatewayPort() and getEffectiveFeedbackPort() to ask for ports.
src/test/java/com/notnoop/apns/utils/ApnsServerStub.java