Yes, it can be done. you can check out the android developers site for more info. Here's a short synopsis of the same:
• Setting up Permissions:
The following permissions would have to be added to the app by modifying
the manifest file: CHANGE_WIFI_STATE, ACCESS_WIFI_STATE,
and INTERNET
• Creating Broadcast Reciever and P2P Manager
This is done by instantiating the following classes:
♠ IntentFilter() : To check for changes in the connection/peers. *Any
problem in connection & changes in the peer list should be detected here
♠ WifiP2pManager() : for managing Wi-Fi peer-to-peer connectivity
♠ BroadCastReciever() :Base class for code that will receive intents
• Obtaining List of peers:
Initiate Peer discovery by giving a call to discoverPeers() method
Implement PeerListListener. Use peerList.getDeviceList() to obtain the list
of peers; and pass it to an arraylist
• Connecting to a peer:
Create a WifiP2pDevice objects, that will store information about each p2p
device
Instantiate WifiP2pConfig object; and copy data into it from the
wifip2pdevice
The detailed description of this process can be found out over here: http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html
I've just tried to simplify & shorten it.
beyond this; you can use traditional socket programming (UserDatagramSocket or DatagramSocket) for communication. One of the connected devices assumes role of group owner; and can be used as the main device.