WiFi connection in Android multiplayer game

I got into my application in the part where I need to exchange data via Wi-Fi between two Android devices. the application is actually a turn-based multiplayer game like chess, and I cannot find how to make a part of the connection. Also help me how to use wifi p2p connection. I already read http://developer.android.com/guide/topics/connectivity/wifip2p.html , but I can not understand these parts:

  • requestPeers () method callbacks onPeersAvailable (). Now how to implement this function?

  • onPeersAvailable () returns a WifiP2pDeviceList object. Now, if I want to show it in a list, how can I convert it to an ArrayAdapter or something else to display it.

  • in client code

    socket.connect ((new InetSocketAddress (host, port)), 500);

this function is called. how it works? Does it automatically get the server IP address? Note: host, port are two ints that are declared but not assigned any value on the site. I don’t know if I need to know the host, port value or is it automatically selected in the InetSocketAddress object.

+3
source share

All Articles