Best communication strategy between Android client

2020-06-20 05:31发布

问题:

I was exploring various methods for implementing communication between a home made TCP/IP server and a Android client application.

Some ideas: - TCP/IP Server bases on JSON - Service with WCF library - Some sort of REST server

What is the beast strategy and libraries to approach this problem?

回答1:

For simple messaging, and status checks, any HTTP based solution would be a much better choice than coming up with your own TCP/IP protocol.

HTTP traffic is significantly less likely to be firewalled, so you will avoid a lot of accessibility and configuration problems.

Whether or not you should use REST, depends on the nature of your application. REST makes a lot of sense for CRUD applications, but make much less sense for other types of applications.



回答2:

Why TCP/IP instead of basic HTTP?

Android has solid support for interacting with the cloud via HTTP - Check out the HttpClient object, and the "SampleSyncAdapter" sample project in the sample code folder of your SDK installation for a handy example.

Choosing a format (XML, JSON, etc) is really up to you, but if you're interested in making your application RESTful (or determining if that's appropriate), a good place to start would be the Google IO talk on Android REST Client Applications.



回答3:

This answer comes a bit late but you can also consider to use Eneter Messaging Framework. It is the lightweight cross-platform framework allowing to implement the communication with messages. For the communication with .NET you can use TCP or HTTP protocols.
Example of the communication between Android and .NET is here.
Technical info you can find here.
I hope it will help somebody.



回答4:

You may use json based objects, serialize and deserialize them and post them to aspx page. A good articles is available here http://www.youritbuddy.com/blog/post/2016/11/14/json-communication-between-android-and-asp-net-c