Keep Port Open - 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开发者_如何学Go 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.
Thanks in advance, James
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.
精彩评论