Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The android code from the demo wifi direct project is able to pass file is unidirectional. ie. you can send file from client to server only. You need furthur modifications to make it work in both direction.</p> <p>EDIT 2:</p> <p>For that you need to know the IP address of both connected peers. Use the following function which I made following various sources with my modifications wherever appropriate.</p> <pre><code> public static String getIpAddress() { try { List&lt;NetworkInterface&gt; interfaces = Collections .list(NetworkInterface.getNetworkInterfaces()); /* * for (NetworkInterface networkInterface : interfaces) { Log.v(TAG, * "interface name " + networkInterface.getName() + "mac = " + * getMACAddress(networkInterface.getName())); } */ for (NetworkInterface intf : interfaces) { if (!getMACAddress(intf.getName()).equalsIgnoreCase( Globals.thisDeviceAddress)) { // Log.v(TAG, "ignore the interface " + intf.getName()); // continue; } if (!intf.getName().contains("p2p")) continue; Log.v(TAG, intf.getName() + " " + getMACAddress(intf.getName())); List&lt;InetAddress&gt; addrs = Collections.list(intf .getInetAddresses()); for (InetAddress addr : addrs) { // Log.v(TAG, "inside"); if (!addr.isLoopbackAddress()) { // Log.v(TAG, "isnt loopback"); String sAddr = addr.getHostAddress().toUpperCase(); Log.v(TAG, "ip=" + sAddr); boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr); if (isIPv4) { if (sAddr.contains("192.168.49.")) { Log.v(TAG, "ip = " + sAddr); return sAddr; } } } } } } catch (Exception ex) { Log.v(TAG, "error in parsing"); } // for now eat exceptions Log.v(TAG, "returning empty ip address"); return ""; } public static String getMACAddress(String interfaceName) { try { List&lt;NetworkInterface&gt; interfaces = Collections .list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { if (interfaceName != null) { if (!intf.getName().equalsIgnoreCase(interfaceName)) continue; } byte[] mac = intf.getHardwareAddress(); if (mac == null) return ""; StringBuilder buf = new StringBuilder(); for (int idx = 0; idx &lt; mac.length; idx++) buf.append(String.format("%02X:", mac[idx])); if (buf.length() &gt; 0) buf.deleteCharAt(buf.length() - 1); return buf.toString(); } } catch (Exception ex) { } // for now eat exceptions return ""; /* * try { // this is so Linux hack return * loadFileAsString("/sys/class/net/" +interfaceName + * "/address").toUpperCase().trim(); } catch (IOException ex) { return * null; } */ } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload