HotSpotSocket是一个运行在Android系统上的应用,实现的功能有:创建热点、关闭热点、打开wifi、关闭wifi、发送接收消息、发送接收文件。
两台手机首先通过一台手机打开热点,另一台连接其热点建立连接。连接之后,两台手机都能得到对方的ip地址,再约定好一个端口号就能建立socket连接。建立socket连接之后,就能通过相应的函数实现文件传输。
- 程序启动之后,启动一个子线程监听9999端口。
- 当发送端点击“发送文件”按钮之后,选择需要发送的文件。选择文件功能通过NoNonsense-FilePicker库实现。
- 发送端获得与其连接的设备的局域网ip。并通过此ip以及9999端口建立socket连接,并开启传输文件线程。
- 接收端一直都在监听9999端口,当有文件传过来时便建立连接自动接收文件。