Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. mfc application hangs

mfc application hangs

Scheduled Pinned Locked Moved C / C++ / MFC
c++sysadminhelp
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abinash Mohanty
    wrote on last edited by
    #1

    Hi, I have created an SDI application in which i am creating a client-server application using Socket Programming.I am connecting with multiple PCs.My application works fine if the remote PC gets connected.But when the remote PC is ShutDown the application hangs during gethostbyaddr function and takes some time to come out of it.If my client application is not running in remote PCs then it gets hang during connect function.Can anybody please help me out of this or suggest a different way to do it.Its urgent. Thanks

    M R M 3 Replies Last reply
    0
    • A Abinash Mohanty

      Hi, I have created an SDI application in which i am creating a client-server application using Socket Programming.I am connecting with multiple PCs.My application works fine if the remote PC gets connected.But when the remote PC is ShutDown the application hangs during gethostbyaddr function and takes some time to come out of it.If my client application is not running in remote PCs then it gets hang during connect function.Can anybody please help me out of this or suggest a different way to do it.Its urgent. Thanks

      M Offline
      M Offline
      Mohan Ramachandra
      wrote on last edited by
      #2

      Establish connection using thread AfxBeginThread . Then your main application thread won't stuck

      A 2 Replies Last reply
      0
      • A Abinash Mohanty

        Hi, I have created an SDI application in which i am creating a client-server application using Socket Programming.I am connecting with multiple PCs.My application works fine if the remote PC gets connected.But when the remote PC is ShutDown the application hangs during gethostbyaddr function and takes some time to come out of it.If my client application is not running in remote PCs then it gets hang during connect function.Can anybody please help me out of this or suggest a different way to do it.Its urgent. Thanks

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        You mean your server connects to multiple clients? :wtf: Shouldn't it be the other way round? And read up on asynchronous sockets (on the server side). That will help you solve the 'hanging' issue. CP has a section for articles on network programming. There's also Beej's Guide[^] which might help in clearing up the basics.

        “Follow your bliss.” – Joseph Campbell

        A 1 Reply Last reply
        0
        • M Mohan Ramachandra

          Establish connection using thread AfxBeginThread . Then your main application thread won't stuck

          A Offline
          A Offline
          Abinash Mohanty
          wrote on last edited by
          #4

          Hi, Thanks for your reply.I have already tried using AfxBeginThread. But i faced a problem with its synchronization.I am connecting with multiple PCs retreiving some information and then adding it to a tree in LeftView of my SDI application.So if i am using threading then it displays wrong information.Please suggest me another way other than this. Thanks

          K 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            You mean your server connects to multiple clients? :wtf: Shouldn't it be the other way round? And read up on asynchronous sockets (on the server side). That will help you solve the 'hanging' issue. CP has a section for articles on network programming. There's also Beej's Guide[^] which might help in clearing up the basics.

            “Follow your bliss.” – Joseph Campbell

            A Offline
            A Offline
            Abinash Mohanty
            wrote on last edited by
            #5

            Hi, Thanks for your reply.But my problem is that my application hangs during gethostbyaddr and connect function which i am using for multiple pcs.Please suggest me a way so that my application takes least time durin the above mentiones operations. Thanks

            E 1 Reply Last reply
            0
            • M Mohan Ramachandra

              Establish connection using thread AfxBeginThread . Then your main application thread won't stuck

              A Offline
              A Offline
              Abinash Mohanty
              wrote on last edited by
              #6

              Hi, Can we give timeout for gethostbyaddr and connect function? Thanks

              1 Reply Last reply
              0
              • A Abinash Mohanty

                Hi, Thanks for your reply.I have already tried using AfxBeginThread. But i faced a problem with its synchronization.I am connecting with multiple PCs retreiving some information and then adding it to a tree in LeftView of my SDI application.So if i am using threading then it displays wrong information.Please suggest me another way other than this. Thanks

                K Offline
                K Offline
                KarstenK
                wrote on last edited by
                #7

                using threads is the right way AND this leads syncronisation issues which you have to solve. You can use messages to your main window) to update the informations. Display some "Updating..." or empty fields til the needed information cames along. :rolleyes:

                Press F1 for help or google it. Greetings from Germany

                1 Reply Last reply
                0
                • A Abinash Mohanty

                  Hi, Thanks for your reply.But my problem is that my application hangs during gethostbyaddr and connect function which i am using for multiple pcs.Please suggest me a way so that my application takes least time durin the above mentiones operations. Thanks

                  E Offline
                  E Offline
                  Emilio Garavaglia
                  wrote on last edited by
                  #8

                  gethostbyaddr requires you machine to contact a DNS server to resolve the address. If your DNS configuration is not correct or if the DNS server takes time to resolve (may be because of several indirections)gethostbyname can only wait the answer or wait for the connection timeout to occur (usually 40 seconds, where TCP is used). Since this call is synchronous, there is no way to run around than multithreading. All the communication tasks should be accomplished by secondary threads that send messages to the primary one (may be through the main window) as things happens, letting the primary one to manage the GUI by updating it and responding to user inputs. Of course, you can set a timer that kills the communication thread if it doesn't signal events after a while, but consider that such "while" is not something you should decide (the response time of the DNS is a network administration parameter that is not relevant only to your application).

                  2 bugs found. > recompile ... 65534 bugs found. :doh:

                  1 Reply Last reply
                  0
                  • A Abinash Mohanty

                    Hi, I have created an SDI application in which i am creating a client-server application using Socket Programming.I am connecting with multiple PCs.My application works fine if the remote PC gets connected.But when the remote PC is ShutDown the application hangs during gethostbyaddr function and takes some time to come out of it.If my client application is not running in remote PCs then it gets hang during connect function.Can anybody please help me out of this or suggest a different way to do it.Its urgent. Thanks

                    M Offline
                    M Offline
                    Moak
                    wrote on last edited by
                    #9

                    Abinash Mohanty wrote:

                    application hangs during gethostbyaddr

                    Hi Abinash! It's a known weakness in MFC's networking classes CAsyncSocket or CSocket, this is what you see when the GUI becomes unresponsive. You would need to implement an asynchronous hostname resolver, otherwise hostname lookups will be blocking everything (they can take quite a while). Btw, if you work with IP-addresses this problem will not occur. As an alternative use one of the many C++ network classes, in alphabetical order: Alhem, Boost, SharkEngine, QT, and many others. Hope this helps! :) /M

                    Webchat in Europe :java: Now with 26% more Twitter

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups