Re: one-to-one client server design
- From: "kondal" <kondal04@xxxxxxxxx>
- Date: 25 Sep 2006 21:10:56 -0700
Capstar wrote:
kondal schreef:
Capstar wrote:
Hi NG,
I'm designing a client server architecture in which the client and the
server have a one-to-one relation.
My first try was to do an accept to obtain the socket to the client and
work on that until the connection is closed. Than I'd call accept again
and to the same thing.
This is not an acceptable solution though since any new connection can
be pending for quite a long time since the server doesn't do anything
with them.
My first solution would be to close the server socket the moment a
connection is established so the entire service would be unavailable for
the duration of the connection. This way new clients will fail to
connect. This solution doesn't feel right since new clients will not
know why the connection failed.
I guess the best way would be to have some handshaking just after a
connection is established to tell the client if the connection is
allowed or not. Although this is easy enough to implement I was
wondering if this is really the way to go or if there's another more
common way of doing it.
Thanks,
Mark
The problem you projected uses N-1 client server relation (N clients to
1 server). It is not one-to-one. If it is one-to-one you do not need to
worry about the other client coming in.
Initial handshake is the general method used. I used token passing
method to all the clients so that they wait till they receive the token
(generally a counter).
Just wondering what would be the reson not to use concurrent
programming method here unless you are accessing a device that is not
concurrent (or similar).
-kondal
I called it a one-to-one relation because the server can only actively
handle one connection. The server runs on a recording system and
commands from a client can change the state of the system. The state is
also persistent between connects.
The design of the system demands that when a client sends a command to
the server that would change the state of the system and the server
acknowledges the command, that the system is from that point on in a
known state. If another client could also connect and change the state
of the system there's no way to be certain what the state of the system is.
OK I understand what you mean. But doesn't it require that the client
should know the present state of the system before sending its command?
I think handshaking would suffice to do what I need. But can you
elaborate on the token passing method? Does this mean that the server
basically asks the client for a command by passing it a token?
This is simple, learned from token system used in banks :) Here are the
following steps.
1. Server keeps on accepting the clients but doesn't responds to its
commands.
2. When a new client connects, the server keeps a counter as how many
clients have connected. Sends this counter to the client. The server
actually makes a list of client and appends a new list item to the
current list.
3. The client first listens to the server's welcome message which
contains a token (counter). By this it understands at what position it
is in. It also helps in UI design to let the user know how long it
takes for the command to process.
4. The client may optionally request for the current counter from the
server to know the status.
5. By default the client is in read state where it is waiting for the
server to send a message that it is ready.
6. The server sends a ready message to the client and the client sends
its command.
7. Once the service is done, the server removes it from the list and
decrements the counter.
8. Sends a ready message to the next client in the list.
There is an advantage in this process. You could also use priority list
so that the server could choose the highest priority requests first.
The decission of which client goes to higher priority is up to you. It
could be a specific client, or based on the ack on the welcome message
send by the server, etc
I used this method in my self project during college days. So there
could be better designs that may be suitable for you. This is just a
suggestion.
Good luck.
-kondal
.
- References:
- one-to-one client server design
- From: Capstar
- Re: one-to-one client server design
- From: kondal
- Re: one-to-one client server design
- From: Capstar
- one-to-one client server design
- Prev by Date: Re: scope of linux in the corporates...
- Next by Date: Re: scope of linux in the corporates...
- Previous by thread: Re: one-to-one client server design
- Next by thread: Re: one-to-one client server design
- Index(es):
Relevant Pages
|