I am trying to implement WiFi-Direct(WiFi-P2P) in Android. I refer to the sample code in samples\android-19\legacy\WiFiDirectDemo .
I install WiFiDirectDemo.apk on phone-A and run it. phone-B enable WiFi-Direct(WiFi-P2P) in Android Setting .
After phone-A connect to phone-B , it will show the following information about phone-A .

And the code is as follows:
@Override public void onConnectionInfoAvailable(final WifiP2pInfo info) { Log.d(WifiP2P.TAG, "onConnectionInfoAvailable----------- " + info); if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } this.info = info; this.getView().setVisibility(View.VISIBLE); // The owner IP is now known. TextView view = (TextView) mContentView.findViewById(R.id.group_owner); view.setText(getResources().getString(R.string.group_owner_text) + ((info.isGroupOwner == true) ? getResources().getString(R.string.yes) : getResources().getString(R.string.no))); // InetAddress from WifiP2pInfo struct. view = (TextView) mContentView.findViewById(R.id.device_info); view.setText("Group Owner IP - " + info.groupOwnerAddress.getHostAddress()); // After the group negotiation, we assign the group owner as the file // server. The file server is single threaded, single connection server // socket. if (info.groupFormed && info.isGroupOwner) { new FileServerAsyncTask(getActivity(), mContentView.findViewById(R.id.status_text)) .execute(); } else if (info.groupFormed) { // The other device acts as the client. In this case, we enable the // get file button. mContentView.findViewById(R.id.btn_start_client).setVisibility(View.VISIBLE); ((TextView) mContentView.findViewById(R.id.status_text)).setText(getResources() .getString(R.string.client_text)); } // hide the connect button mContentView.findViewById(R.id.btn_connect).setVisibility(View.GONE); }
phone-A - Group Owner . And I want to send TCP data from phone-A to phone-B .
1. How to get the IP address of phone-B .
2. Group Owner IP value means IP address of phone-A
source share