2

我创建了一个用于传输数据的 android - 桌面套接字编程。套接字通信是基于双工的,其中客户端在 android 上,服务器在桌面上。一次可能有很多安卓客户端连接到桌面服务器。应用程序在某些方面运行良好,我觉得一些问题是连接中断,因为我使用的是 WiFi,需要传输大量数据时速度很慢。

最近我了解了 REST Web 服务,我创建了一个应用程序,其中 Web 服务在本地桌面计算机上运行,​​android 应用程序通过 HTTP POST 和 HTTP GET 连接到它,并从任何一方传输数据。

我想知道是Socket编程更好还是webservice更适合本地通信和批量数据交换?哪个更快?

谁能告诉我一些解决方案?

4

1 回答 1

3

Sockets are faster than web services in general.

  1. As you master both sides of the communication you can have your own data format, which can be much more efficient than what you're allowed to do with http
  2. Depending on what you're sending, you may have a very simple message structure, whereas http will always require its header for example, which adds data to transfer
  3. Classic http is opening and closing the communication channel for each request, which is quite inefficient

However, on this last point as you're on a slow, unstable wifi connection it is not bad to reconnect for each request.

I would recommend you to have a look to zmq, it is a library for message queues between applications with a great variety of supported topologies. There are bindings for a lot of languages, and it also works on Android. You may find it better than plain sockets + your own message protocol, or http.

于 2013-10-06T03:34:09.633 回答