开发者

Persistent TCP connection client / server

I'm building a client server application from an android device to a server over 3G. Because of the network operator that is providing 3G, the client device is behind a NAT. Therefore, it is impossible for the server to make a connection to the client. I could adopt an approach of polling, however before doing so, I want to exhaust all other options. Is there some way ( I haven't yet found one ) to keep a TCP Socket connection open between the client and server, such that the server would be able to initiate communications to the client?

The scenario is that there will be very regular client/server communication based on server state that updates on a开发者_运维百科n extremely regular basis - we would be talking every couple of seconds. Would UDP be a better option here? Maybe not as the NAT issue still knocks it on the head.

Are there any other options available to me?

Many thanks


NAT does not mean that the server can not send anything. Just open a connection from the client and let the server send whatever events it records. You may also want to include a simple heartbeat protocol to make client and server register a broken connection and to make the NAT aware that the connection is still being used.


Just open a socket and use it, including the ObjectOutputStream. If the intermediate systems drop the connection you will get an exception, whereupon you close and repeat.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜