I have an issue which I can't even start to solve after hours of researching. I need to use GCM to facilitate peer to peer file transfer (JPEG image of circa 1.5 megabytes in file size to be specific).
Client A opens a socket and uses AirBOP to notify client B that it wants to send a picture and gives B relevant information (IP address + port to use, ephemeral I guess). B then connects to A and downloads the picture. All this behind NAT and via 3G/4G if at all possible. No server involved.
I looked into TTorrent, Snark, Cling, NAT hole punching, PWnat etc. but I still don't know how to achieve the above, and if it is possible at all. What i did understand is that i will need to use port mapping or UPNP.
Sorry for poor English, and I'm looking for a road map/guide lines/library/existing tutorials/projects on solving the above problem.
Thank you.
Google Cloud Messaging (GCM) was not designed to deliver large payloads. It's intention was to provide a light-weight messages for your application to then handle the heavy lifting (e.g. a new email notification informing your application it is out-of-date and that it should retrieve the new email). With that said, it does however have the ability to carry a payload of up to 4Kb. Which is obviously not enough to handle your 1.5Mb payload. You might think about implementing some type of protocol that will assemble the complete payload after x number of GCM messages. First, there is a quota on the number of GCM requests allowed per day per ip address. Second, GCM explicitly does not want its service to be used in this way and will block GCM messages if it detects it is being used that way. See http://developer.android.com/google/gcm/adv.html for more information.
What you need to implement a p2p application is either a STUN server or TURN server. A STUN server is used to discover the public IP and port that is being used by the device to communicate with the internet. You can either implement your own STUN server but requires a server that is publicly accessible/routable from both peers or use a public STUN server and use GCM to notify each peer of the others public ip and port. A major limitation with this technique is that if one of the devices is behind a router/NAT that has been configured to use symmetric nating, it will not punch through. There are exceptions to this but generally this is the case. Using a TURN server basically just relays the data from one peer to another peer via a central/public server. This isn't much of a challenge except it will cost you since this type of solutions puts a heavy load onto the server as oppose to a STUN server and you may need to purchase several servers to handle your user load.
I'm in the middle of my own p2p project and what I've discovered is that Verizon implements Port-retricted cone nat, AT&T symmetric cone nat, Sprint symmetric cone nat. Considering the popularity of mobile carriers (Verizon #1, At&t #2, Sprint #3), this is something to consider.
STUN Protocol https://www.rfc-editor.org/rfc/rfc5389