How to Transfer Files Between Android and iOS using TCP?

By: Jiten
Updated: June 3rd, 2019 | Technology: App Developer
Files Transfer Between Android and iOS using TCP

Hi Developers,

I am going to share the best way to transfer files between Android and iOS. I shared the full code for working on cross-platform file sharing (between Android and iOS) issues and solutions.

When I worked in Android app project, I was restricted to use Lollipop OS due to Java 8 is not supported in it. So, you may or may not face the same issue depending on what you are trying to achieve.

First of all, Let’s define what jReto and SReto is?

  1. jReto: P2P Framework for real-time collaboration in Java.
  2. SReto: P2P Framework for real-time collaboration in Swift.

Reto is an extensible P2P network platform used in Java 8 and Swift. It delivers the APIs in both languages.

The features of this frame are:

  • Peer discovery
  • Putting connections between peers
  • Acting cancellable data transfers
  • Features assistance for routed connections (i.e., peers that Can’t directly communicate could Nevertheless Be found and utilize other peers to forward information)

This module allows peers to discover one another and discuss over the Web that a RemoteP2P server is necessary.

  1. WLAN module: Enables peer discovery and connectivity in LAN (Local Area Networks) by using Bonjour for detection (locating) and regular TCP/IP connections for information transfers.
  2. RemoteP2PModule: Uses an internet server to facilitate communication between peers. This module enables peers to discover one another and discuss over the Web; Still, that a RemoteP2P server is required.

Now! Let’s short it down in our example.

jReto (Android) /SReto ( iOS ) + Bonjour service: Finding devices and sending objects.

We used Bonjour discovery to find out nearby running the same services to send and receive files for cross-platform file sharing. We can act as server and client by broadcasting and seeking service usage.

Here I prepared a code of it. So, you can use it directly into your project or application. i.e. android is broadcasting ( advertising ) service, which can be discovered by the client.

Android Java Broadcaster:

iOS Swift Broadcaster:

  • Only the same name service can be discovered by the client to connect with.
  • Once we found broadcasting service from the server we can go ahead and can connect to the server.

  • i.e Android broadcasted it’s service and iPhone ( which is seeking for service to get connected with ) found service with on the same network tries to connect with.

  • Once the connection is established, we tried to share files from one platform to another ( here iOS to Android ).

Receiving Data on Android:

Sending Data from iOS:

  • We observed that file which is being transferred on TCP connection are chunked into small bytes which created an issue on the android side to read ( due to heap memory issue ).

  • Which was not helpful to share a large file between two devices.

Final Workaround:

  • After facing the above issue, we tried many ways including web socket as well, but due to its file transfer speed issue wasn’t that handy technique to implement.
  • We decided to simply create an observer and listener with the same connection name.
  • After that, we tried to connect and shared a file using fast socket from iOS to Android.

  • Which turned out to be helpful.
  • The only issues we found that we can not pass the header file along with the file to identify the file type.

Guys, I hope you like my article. I intend to save your time and helping other developers to solve the same issues during the mobile applications development.

Request a Free Quote

Looking for a solution to your mobile applications?

Let’s have a meeting with our mobile app developers and work together for your problems.

Request a Free Quote