I'm developing an Android application that needs to send local data to the Chromecast device. The Cast.CastApi.sendMessage()
method works fine for small messages (up to about 100KB, it seems) but I need to pass images that may be several MB in size.
It seems that the best way is to bind to a local port on the Android device and listen for connections, pass a URL that points to the Android device in a message, and have the Chromecast fetch the images that way.
The problem is that I don't know what IP address to include in the URL. The Android device may have several IP addresses, not all of which are reachable from the Chromecast. There are two possible solutions I can think of but don't know how to implement either of them:
- Extract on the Android the local IP address from the socket that is currently connected to the Chromecast. Use that as the host field in the URL.
- Extract on the Chromecast the remote IP address from the socket that is currently connected to the Android. Send a dummy host from the Android and have the Chromecast substitute the correct address it has extracted.
Any suggestion on how to actually accomplish either of these? Or another option?