-3

I want to send a data file to my Android app. I can send from Android to server but I can't send to Android. I am trying to use ServerSocket in the Android app but when I try to connect from my C# app I get a connection error.

Notes:

  • The Android app connects to internet with the telephone operator's internet service.
  • The C# app connects to internet with another internet service provider.

I would like a simple example.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Regalo
  • 1
  • 5
  • 1
    Generally, your phone will get a dynamic IP address (or NAT private IP address), which will make it for your server not easily possible to find and initiate a conversation with your phone. The best practice is to have the server to wait for a conversation initiated from your phone. Your server will have a fixed IP address or host name. – tofi9 May 13 '14 at 14:30
  • I think u mean pc server. But it is not valid for my projecjt. I am doing queries from android.The query send by Android App.C# server app gets query and send result to android app. – Regalo May 13 '14 at 14:37
  • You basically can't do that - not because of Android, but because the mobile network provider won't pass incoming connections through. So you have to rethink your scheme to work in the other direction, either having the Android query or using something like the already mentioned GCM to prompt it to query. – Chris Stratton May 13 '14 at 14:46
  • I send results as html file.The file size has just about 1.5 mb. Can i send this file to use GCM service? – Regalo May 13 '14 at 14:58
  • The website's frontpage states in the first paragraph "a message containing up to 4kb of payload data". Normally you use push notifications to notify your phone with the message "hey, there is new data. If you're interested, and you've still got enough battery juice, and your user is OK with background data transfers, then: call back home to get the data" – tofi9 May 13 '14 at 15:02
  • ok actually how to provide gcm this ? does it use google server ? – Regalo May 13 '14 at 15:07
  • @Regalo: correct 100%. The idea is that many apps on the phone will use GCM. Therefore, the phone only has to maintain one single connection with the GCM server in order to receive notifications for all apps installed. A huge battery&data saver. – tofi9 May 13 '14 at 15:10
  • understood but 4 kb is not suitable for my project i must find an other solution – Regalo May 13 '14 at 15:22

1 Answers1

2

Generally, your phone will get a dynamic IP address (or even worse, a NAT private IP address) from the phone network provider, which will make it for your server not easily possible to find and initiate a conversation with your phone.

The best practice is to let the server wait for conversations that are initiated by your phone. Your server will have a fixed IP address or a well-known host name. This practice is known as calling home.

If your phone wants to keep up-to-date with server notifications and ends up calling home often, this will eventually increase the data usage on the phone network and decrease the battery life. A solution to this problem is to use push notification services.

tofi9
  • 5,775
  • 4
  • 29
  • 50