Thread advice needed - Programmer

This is a discussion on Thread advice needed - Programmer ; I am new to C++ and Windows programming and I am developing a client-server application. The application has an MFC dialog client app which speaks to a remote server application. As it involves communicating over the Internet my initial thoughts ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Thread advice needed

  1. Thread advice needed

    I am new to C++ and Windows programming and I am developing a client-server
    application.

    The application has an MFC dialog client app which speaks to a remote server
    application. As it involves communicating over the Internet my initial
    thoughts are to have the client-side communication being done in a thread of
    its own.

    The client application has the GUI dialog class which instantiates a
    "manager" class. All network communication is done via methods in the
    manager class.

    How do I implement threading in this network communication (so that the
    program doesn't freeze when it's waiting for network responses)? Do I modify
    the manager class so that it inherits from a thread class (i.e. does the
    manager class become a thread)? What thread class should I use? How do I
    start the thread in the GUI? How do I access the thread from within the GUI?

    *Any* advice regarding threads related to this type of application would be
    greatly appreciated.

    Thanks in advance.



  2. Re: Thread advice needed

    Steve wrote:
    > I am new to C++ and Windows programming and I am developing a client-server
    > application.
    >
    > The application has an MFC dialog client app which speaks to a remote server
    > application. As it involves communicating over the Internet my initial
    > thoughts are to have the client-side communication being done in a thread of
    > its own.
    >
    > The client application has the GUI dialog class which instantiates a
    > "manager" class. All network communication is done via methods in the
    > manager class.
    >
    > How do I implement threading in this network communication (so that the
    > program doesn't freeze when it's waiting for network responses)? Do I modify
    > the manager class so that it inherits from a thread class (i.e. does the
    > manager class become a thread)? What thread class should I use? How do I
    > start the thread in the GUI? How do I access the thread from within the GUI?
    >
    > *Any* advice regarding threads related to this type of application would be
    > greatly appreciated.
    >
    > Thanks in advance.


    I try to keep it simple. I have a worker thread managing the network,
    and use WM_USER type messages to let the UI thread know that something's
    happened. There are probably more elegant/cleaner solutions, but mine
    seems to work.

  3. Re: Thread advice needed

    "red floyd" wrote in message
    news:uU1$%23%23N1FHA.2964@TK2MSFTNGP09.phx.gbl...

    > I try to keep it simple. I have a worker thread managing the network, and
    > use WM_USER type messages to let the UI thread know that something's
    > happened. There are probably more elegant/cleaner solutions, but mine
    > seems to work.


    How do you implement the thread? When you say "thread" do you mean a class
    inheriting from a thread class?



  4. Re: Thread advice needed

    There are a couple answers.

    The easiest one is to use CAsyncSocket (never, ever, consider CSocket or any form of
    synchronous socket communication if you expect to produce a reliable result. Synchronous
    sockerts in and of themselves are Really Bad Ideas for reliable code, and CSocket is
    reported to be buggy and unusable). Then you don't really need a separate thread. The
    main GUI thread won't freeze, and it will receive asynchronous notifications when messages
    come in. Also remember that "messages" means "bytes from the network" and if you want to
    im;pose any structure on those messages, you are responsible for parsing them and
    extracting the information. If the server sends a string of bytes which I'll call ABC,
    you might receive A, B, C as three individual notifications, AB, C as two notifications,
    A, BC as two notifications, or ABC as one notification. The network is free to split your
    byte stream at any boundary it feels like based on network properties and instantaneous
    network traffic patterns. Then let A, B and C represent arbitrary substrings of bytes and
    the problem generalizes.

    If you want to use a separate thread for the sockets, see my essay on the use of UI
    threads on my MVP Tips site, which shows the protocol for passing sockets across threads.
    Then to request a thread service you would PostThreadMessage a request to the UI thread.

    Always think totally-asynchronous data-flow models. As soon as you introduce the concept
    of synchrony, you're dead.
    joe

    On Wed, 19 Oct 2005 18:50:17 GMT, "Steve" wrote:

    >I am new to C++ and Windows programming and I am developing a client-server
    >application.
    >
    >The application has an MFC dialog client app which speaks to a remote server
    >application. As it involves communicating over the Internet my initial
    >thoughts are to have the client-side communication being done in a thread of
    >its own.
    >
    >The client application has the GUI dialog class which instantiates a
    >"manager" class. All network communication is done via methods in the
    >manager class.
    >
    >How do I implement threading in this network communication (so that the
    >program doesn't freeze when it's waiting for network responses)? Do I modify
    >the manager class so that it inherits from a thread class (i.e. does the
    >manager class become a thread)? What thread class should I use? How do I
    >start the thread in the GUI? How do I access the thread from within the GUI?
    >
    >*Any* advice regarding threads related to this type of application would be
    >greatly appreciated.
    >
    >Thanks in advance.
    >

    Joseph M. Newcomer [MVP]
    email: newcomer@flounder.com
    Web: http://www.flounder.com
    MVP Tips: http://www.flounder.com/mvp_tips.htm

+ Reply to Thread