mfc application hangs
-
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
-
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
Establish connection using thread AfxBeginThread . Then your main application thread won't stuck
-
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
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
-
Establish connection using thread AfxBeginThread . Then your main application thread won't stuck
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
-
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
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
-
Establish connection using thread AfxBeginThread . Then your main application thread won't stuck
Hi, Can we give timeout for gethostbyaddr and connect function? Thanks
-
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
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
-
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
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:
-
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
Abinash Mohanty wrote:
application hangs during gethostbyaddr
Hi Abinash! It's a known weakness in MFC's networking classes
CAsyncSocket
orCSocket
, 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! :) /MWebchat in Europe :java: Now with 26% more Twitter