Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.development.apps > #310

Re: socket client thread

From Bill M <wpmccormick@just_about_everywhere.com>
Newsgroups comp.os.linux.development.apps
Subject Re: socket client thread
Date 2011-12-13 15:32 -0600
Organization A noiseless patient Spider
Message-ID <jc8g9k$3te$1@dont-email.me> (permalink)
References <jc5vcg$da4$1@dont-email.me> <jc7dtr$gk1$2@reversiblemaps.ath.cx>

Show all headers | View raw


On 12/13/2011 5:46 AM, Jasen Betts wrote:
> On 2011-12-12, Bill M<wpmccormick@gmail.com>  wrote:
>> Hello,
>>
>> I'm working on socket client/server apps where the client app starts the
>> connection on a separate pthread and then sits in a loop to send messages.
>>
>> The problem I'm having is finding how to kill the client app when the
>> server dies. If I use telnet has the client, he does exit.
>>
>> So, in pseudo-code ...
>>
>> start_client() //starts client connection on another thread
>>
>> while(!quit&&  connected) {
>> 	
>>     message = get_user_message
>>
>>     //this blocks
>>     reply = send_message_to_server(message)
>>
>>     print(reply)
>> 		
>> }
>>
>>    ...
>
>> What is the usual method to know the server is still alive?
>
> to test if a thread is alive, send a null signal:
>
>    pthread_kill(client_thread,0);
>
> also if it has died you should also get an error on the socket.
>

Thanks! Neither solution is really what I'm looking for but the 
pthread_kill solution gives me an idea for something else. What I 
decided to do was to allow the client to continue to run (after a dead 
server detect) and attempt to periodically reconnect.

What I see is that select() will return 1, even on a socket file 
descriptor that has closed. Then, recv(sockfd, ...) returns 0 bytes. At 
this point I close sockfd and attempt to reconnect.

Thanks Again!

Back to comp.os.linux.development.apps | Previous | NextPrevious in thread | Find similar


Thread

socket client thread Bill M <wpmccormick@gmail.com> - 2011-12-12 16:31 -0600
  Re: socket client thread David Schwartz <davids@webmaster.com> - 2011-12-12 18:35 -0800
  Re: socket client thread Jasen Betts <jasen@xnet.co.nz> - 2011-12-13 11:46 +0000
    Re: socket client thread Bill M <wpmccormick@just_about_everywhere.com> - 2011-12-13 15:32 -0600

csiph-web