Re: long lasting client socket connection



Rainer Weikusat wrote, On 1/13/2012 4:17 PM:
Bill M<wpmccormick@xxxxxxxxxxxxxxxxxxxxxxxxx> writes:

[...]

The client application is multi-threaded; each thread makes a socket
connection and keeps it open. Client threads continuously send
requests to the server, and then wait for a pthread condition when the
reply (terminated with \n) comes in, or it time times out.

A problem occurred when a client actually timed-out and the data came
in right after that, so then the next client that sent a request got
the reply for the previous, and so on from that point on. (The client
supplies the read buffer.)

As stated, this is not possible: If each client uses a connection of
its own, no client can ever receive a reply for another client.

I think this is the key comment. I need to re-think my design. Looking at things again, what I really have is a single client thread that multiple (other) threads are sharing. I need to re-code this so that each thread actually has it's own client. I'm trying to do this with code from a generic client object (that I also wrote). I need to figure out how to code this so that each client thread get's it's own copy of things like a file descriptor, sockaddr_in, and client state in general.



Apart from that: If you think you need application level timeouts with
TCP then you need to destroy and recreate the connection after a
timeout occurred: Otherwise, you will either get all replies in the
order they were sent no matter if the client still wants them or not
or a transport layer connection abort after 'a long time'. TCP isn't
(and isn't designed to be) suitable for communication with realtime
requirements. Consider using UDP, possibly with a suitable
retransmission scheme.


Given that each client "send" expects a reply, and that the "sends" are continuous, the I still think a connected TCP socket is the right way to do this. I just need to code it so that if a client attempts to send and errors occur before the reply is received, then the existing connection is torn down; a new one is built; and the send is attempted again.

Thanks!!
.



Relevant Pages

  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #3]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... kernel socket family. ... presentation side is left to the client. ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • Re: callbacks in TAO
    ... Most firewalls do not restrict access by inbound port number. ... Lets say your client application terminates while it still has the connection open. ... requests at the same time, the second thread will open a new connection if the existing connection is busy. ...
    (comp.object.corba)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #2]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • Re: Learning how to use "Remote Login"
    ... for client connection requests. ... "listening", by your definition. ... who listens for client requests. ...
    (comp.sys.mac.system)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)