保持端口开放 - iPhone

发布于 2024-11-27 01:03:53 字数 403 浏览 0 评论 0原文

我有两台服务器(家庭服务器和远程服务器)和 iPhone 上的程序。 iPhone需要保持一个端口开放直到整个过程完成,否则整个系统将会失败。

因此,iPhone 从“本地”服务器获取一串数据(通过 post),向其中添加一些内容,然后通过端口流连接到“远程”服务器。一旦端口打开并将数据发送到“远程”,它就会从远程获取响应并将其转发到“本地”。一旦“家”收到它,它会改变一些事情并将其发送回 iPhone,iPhone 需要通过相同的、仍然打开的端口将信息转发到“远程”。

我无法关闭端口流并将其重新打开,因为“远程”服务器上的内容会更改并破坏整个过程。

这是一张快速图片。谢谢你,画图女士。 服务器连接

提前致谢, 詹姆斯

I have two servers (home and remote) and the program on the iPhone. The iPhone needs to keep a port open until the entire process is complete, otherwise the whole system will fail.

So, the iPhone gets a string of data from the "home" server (via post), adds some things to it, and connects to the "remote" server via a port stream. Once the port is opened and the data is sent to "remote", it gets a response back from remote and forwards it to "home". Once "home" gets it, it changes some things around and sends it back to the iPhone which needs to forward the information to "remote" via that same, still opened, port.

I can't close the port stream and open it back up because things on the "remote" server will change and break the entire process.

Here is a quick picture. Thank you, MS Paint.
Server Connection

Thanks in advance,
James

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女净妖师 2024-12-04 01:03:53

如果您同时控制本地和远程服务器,则可以确保使用 HTTP 1.1 并且连接使用“Keep-Alive”标头。

另一种可能有帮助的技术是 XMMP 绑定,用于模拟长期双向的语义联系。

如果您无法控制服务器,那么我担心您有点孤军奋战,因为 Keep-Alive 的引入是为了支持持久或长期连接。

在这种情况下,我认为保持连接打开的唯一选择是某种轮询,即,当 iPhone 等待一台服务器的响应时,它每 n 秒向另一台服务器发送一个请求,即n 下面的服务器连接超时。

仅当服务器在发送响应后没有立即关闭连接时,此方法才有效。

If you control both the local and remote server, you could ensure that HTTP 1.1 is used and that the connection uses the "Keep-Alive" header.

A technique that could also help is XMMP binding to emulate the semantics of a long-lived bidirectional connection.

If you don't have control over the servers, then I fear you are a bit on your own, since Keep-Alive was introduced rightly for supporting persistent or long-lived connections.

In this case, I think that the only option you have for keeping the connection open is some kind of polling, i.e., while the iPhone is waiting for the response from one server, it sends a request to the other server every n seconds, being n below the server connection timeout.

This approach will work only if the server does not immediately close the connection after sending the response.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文