简体   繁体   English

在应用程序和服务器之间打开连接

[英]Open connection between app and server

I want to create connection between app (in mobile device) and server. 我想在应用程序(在移动设备中)和服务器之间创建连接。

Also it would be great to send some info at a time to app and that server would know if that info reached app. 一次向应用程序发送一些信息也很好,那台服务器会知道该信息是否到达应用程序。

Has anyone tried this? 有人尝试过吗?

I would appreciate for any information. 我将不胜感激。

I've tried that for iOS, actually it was an app that required synchronising several devices across a network. 我曾尝试过将它用于iOS,实际上这是一个需要在网络上同步多个设备的应用程序。

To achieve what you want you need to use sockets. 要实现您想要的功能,您需要使用套接字。 There are two kinds of sockets: TCP and UDP . 有两种套接字: TCPUDP These are protocols that run on the protocol OSI layer. 这些是在协议OSI层上运行的协议。 Read more about TCP/IP stack here . 在此处阅读有关TCP / IP堆栈的更多信息。

When you read all this you will understand why you need to use sockets, and specifically TCP sockets, which are the ones than can ensure delivery. 阅读所有这些内容后,您将了解为什么需要使用套接字,特别是TCP套接字,这些套接字可以确保交付。

For iOS, I recommend using CocoaAsyncSocket , a third party library that substantially leverages the hassle of using sockets at a low level. 对于iOS,我建议使用CocoaAsyncSocket ,它是一个第三方库,该库充分利用了在较低级别使用套接字的麻烦。 For Android I can't tell you right away, but I've used java.net.socket in the past with success, but I'm sure a google search will point you in the right direction. 对于Android,我无法立即告诉您,但是过去我曾经成功使用过java.net.socket,但是我敢肯定Google搜索会为您指明正确的方向。

For Android: 对于Android:

You can use HttpUrlConnection or HttpClient . 您可以使用HttpUrlConnectionHttpClient More here. 这里更多。
To send info from server to device use GCM 要将信息从服务器发送到设备,请使用GCM

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM