sPFWFDMid/src/main/java/it/polimi/spf/wfd/WifiDirectMiddleware.java
public void init() {
        WfdLog.d(TAG, "Called init()");

        initAndStartHandler();

        try {
            mPort = this.requestAvailablePortFromOs();
        } catch (IOException e) {
            mListener.onError();
            return;
        }

        mManager = (WifiP2pManager) mContext.getSystemService(Context.WIFI_P2P_SERVICE);
        mChannel = mManager.initialize(mContext, Looper.getMainLooper(), new WifiP2pManager.ChannelListener() {
            @Override
            public void onChannelDisconnected() {
                WfdLog.d(TAG, "Channel disconnected");
            }
        });

        mReceiver.register(mContext);
        NineBus.get().register(this);
    }
public void init() {
        WfdLog.d(TAG, "Called init()");

        initAndStartHandler();

        try {
            mPort = this.requestAvailablePortFromOs();
        } catch (IOException e) {
            mListener.onError();
            return;
        }

        mManager = (WifiP2pManager) mContext.getSystemService(Context.WIFI_P2P_SERVICE);
        mChannel = mManager.initialize(mContext, Looper.getMainLooper(), new WifiP2pManager.ChannelListener() {
            @Override
            public void onChannelDisconnected() {
                WfdLog.d(TAG, "Channel disconnected");
            }
        });

        mReceiver.register(mContext);
        NineBus.get().register(this);
    }
Method called by {@link WFDMiddlewareAdapter#connect()}