I want to programmatically transfer a file from a Raspberry Pi with Wi-Fi access, running Linux (client), to an Android phone (host). I'm using this link as a guide for how to set up a P2P connection on Android, but I cannot find any references to handle the client side on non-Android devices. I understand I can use this link to provide documentation on connecting the client to the host, but I have no leads on how to actually send a file with it.
Essentially, what I'd like to know is: Is there anything I can do on Linux to get the same effect as this, from the Android documentation? Am I completely misguided?
/**
* Create a client socket with the host,
* port, and timeout information.
*/
socket.bind(null);
socket.connect((new InetSocketAddress(host, port)), 500);
/**
* Create a byte stream from a JPEG file and pipe it to the output stream
* of the socket. This data is retrieved by the server device.
*/
OutputStream outputStream = socket.getOutputStream();
ContentResolver cr = context.getContentResolver();
InputStream inputStream = null;
inputStream = cr.openInputStream(Uri.parse("path/to/picture.jpg"));
while ((len = inputStream.read(buf)) != -1) {
outputStream.write(buf, 0, len);
}
outputStream.close();
inputStream.close();
Edit: Perhaps I'm sleepy, but if the devices are connected, is there a way to simply treat it similarly to this? Android documentation states it supports UPnP and Bonjour as services, if that can provide any direction. If so, is there anything I should be looking out for when transferring large-ish (max 5Gb) files? If it's unrelated, I apologize.
Edit 2: The solution for establishing a connection was in wpa_cli
Particularly, the commands p2p_find
to discover, p2p_peers
to see what found it, and p2p_connect <MAC_of_peer> pbc go_intent=0
to stop searching and connect to the Android host. You can see it show up as a local network with ip a
. However, now I seem to be having a problem on the Android side, and the adventure continues in this question.
The solution for establishing a connection was in wpa_cli
Particularly, the commands p2p_find
to discover, p2p_peers
to see what found it, and p2p_connect <MAC_of_peer> pbc go_intent=0
to stop searching and connect to the Android host. You can see it show up as a local network with ip a
. However, now I seem to be having a problem on the Android side, and the adventure continues in this question, for anyone interested.