public void sendError(int err, int id) {
        ByteBuffer buf = ByteBuffer.allocate(6);
        buf.put((byte) 8).put((byte) err).putInt(id);
        try {
            gatewayOutLock.acquire();
            gatewayOutputStream.write(buf.array());
            gatewayOutputStream.flush();
        } catch (Exception ex) {
            LOGGER.warn("An error occured with accessing gateway", ex);
        }
    }
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