Re: long lasting client socket connection
- From: Kaz Kylheku <kaz@xxxxxxxxxxx>
- Date: Thu, 12 Jan 2012 22:21:25 +0000 (UTC)
On 2012-01-12, Bill M <wpmccormick@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I'm working on a socket client app that makes a connection to a server
and leaves it open. Thinking that since he's repeatedly asking
questions, there's little point in wasting time closing and reopening
again. Are there any good design patterns out there for this I should
take a look at?
Yes, the Null Node Pattern: when you don't want something to happen
(like closing and re-opening), then omit the lines of code that would cause
that to happen.
:)
But seriously, noe thing you have to watch out for is keeping such connections
idle for too long. It's almost impossible to avoid such an application being
deployed by someone in a scenario where the client connets trhough one (or
more) NAT gateways to the server. When these routers don't see any activity
between a pair of destinations, they will expire the mapping entry, and then
your connection is gone.
So you might want to include in your design the provision for keepalive
ping messages (in either direction: server or client initiated).
You probably need some kind of layered design: some objects representing the
server session, which hides a protocol for exchanging multiple messages with
the server within one session.
That layer can hide the connecting and re-connecting from the higher
application layers.
.
- Follow-Ups:
- Re: long lasting client socket connection
- From: Rainer Weikusat
- Re: long lasting client socket connection
- References:
- long lasting client socket connection
- From: Bill M
- long lasting client socket connection
- Prev by Date: long lasting client socket connection
- Next by Date: Re: long lasting client socket connection
- Previous by thread: long lasting client socket connection
- Next by thread: Re: long lasting client socket connection
- Index(es):
Relevant Pages
|