Re: A beginner's question on thread

From: Aurelio Martin (amartin_at_wpsnetwork.com)
Date: 04/06/04


Date: Tue, 06 Apr 2004 10:31:31 +0200


Timothy Wu wrote:
> I'm writing a small utility that listens for socket connections, and
> also repond to user inputs via a text menu selection.
>
> In order to respond to both the user and the incoming connections I
> figure I need to use thread.
>
> I think I would use the main thread to handle the menu and spawn a
> thread which listens on a socket.
>
> Now my question is, how do I terminate the server thread if user wants
> to exit the application? If the server just sit there and listen the
> thread would never terminate by itself. What kind of inter-thread
> communications are available and where would I find info/tutorial on that?
>
> Timothy
>

Well, when the user wants to exit, the main thread could open a socket
connection to the server thread, and send a special message telling it
to stop.

The server thread would have to distinguish between normal connections
from clients and special connections from the main thread.

Hope this helps

        Aurelio



Relevant Pages

  • Re: How to implement a daemon like xinetd?
    ... |> the subprocess is needed) for other connections. ... socket() creates the ...
    (comp.os.linux.development.system)
  • Re: How to implement a daemon like xinetd?
    ... |> the subprocess is needed) for other connections. ... socket() creates the ...
    (comp.os.linux.development.system)
  • Asynchronous Socket Server data
    ... The socket server knows what type of data it expects due to the interface ... I can have 1 databuffer only for each datatype to handle multiple connections? ... int bytesRead = handler.EndReceive; ... packetIndex, bytesRead); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Ping =?ISO-8859-1?Q?kr=E1ft=E9=E9_=3F_Advice_needed_?= =?ISO-8859-1?Q?to_trace_w
    ... He has two telephone extensions leading from the master socket and his ... presume that there is a fault in his extension wiring. ... If it's twisted pair ensure that it's not been connected split pair, in other words the blue white with white blue, orange white with white orange, if you get my drift, & the connections you should use are 2&5 ...
    (uk.telecom.broadband)
  • Re: !EventConnect Problem
    ... the June roll-up is available somewhere, although there's not been the usual ... The socket is not in a listening state. ... The incoming connection queue has no room for connections. ...
    (microsoft.public.windowsce.app.development)