Years ago to study how Android to achieve wireless communication function, wrote a small demo, recently nothing, so tidy up, and share with you. Earlier research found that Android want to achieve wireless communication has the following several technologies: 1,bluetooth has long been, easy to use, helpless speed is a mishap; 2,NFC, the official start from API 9, but the vendors are on the sidelines, such as my Samsung does not have the corresponding NFC hardware, NFC applies near-field small data transfer, the performance of the data volume has not yet been tested, but NFC so-called near-field requirements for the distance is very harsh, the basic is to be affixed to the transfer; 3,wifi-p2p, transmission speed, and peer-to-peer so that the two devices are C/S, transmission can be two-way, the official starting from API 14 support, In view of the current API 14 under the equipment maintenance is huge, can only temporarily abandon this technology.
Weigh, refer to the current types of wireless Express software, the final determination to use WiFi AP mode, self-test compatible API 8 devices, transmission speed, but only one-way transmission. The client side is connected via WiFi to the open WiFi AP on the server side, and the client initiates an HTTP request via Httpengine to the server via a simple httpserver to provide response services to the client. The following is a non-standard flowchart to outline the program flow:
Before uploading the project, briefly explain some of the important classes in the source code:
Client Side
Wifiapclientmanager: The interface of the Wifimanager is encapsulated to facilitate the operation of opening, connecting, etc.
Httpenginelite: "Engine" class that initiates an HTTP request
Wifiapclientrequest: Request abstract class, subclass Wifiapclientgetrecvlistrequest, Wifiapclientgetfilerequest to get the server-side file list request and get server-side specified file requests, use Httpenginelite to perform specific actions
Nanohttpclient: Provides a list of server-side files to be sent, access to the server-side specified files, and other operational interfaces, using thread pooling management Wifiapclientrequest
Server Side
Wifiapservermanager: The interface of the Wifimanager is encapsulated so that the AP can be opened and the AP can be configured.
Wifiapserverutil: Defines the Android AP Universal Gateway IP
NANOHTTPD: This class is a reference to open source code (A simple, tiny, nicely embeddable HTTP server in Java)
NANOHTTPSERVER:NANOHTTPD, implements its interface, returns the corresponding HttpResponse
Read The fucking source code:
http://files.cnblogs.com/zealotrouge/WifiAPDemo.7z
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/