[Solved]My CAsyncSocket class doesn't receive data after some secondes. [modified]
-
Hi everybody: I am greenhand in socket programming. I want to write a little program to receive tcp data and save them from server with multi port(almost 64 ports),the data was in deferent data rate.I read msdn and decided to use CAsyncSocket.I wrote a simple class CMySocket,and overide the OnReceive function.In the function,I want to save the received data to file. When I used the new class,I created 64 CMySocket objects,and connect to the server ports.They connected the server well,and OnReceive function was triggered.But after some seconds,for example 10 seconds or handreds seconds,some objects' OnReceive was never triggered any longer,at last all objects were still ,no data incomed. I have no idea why my objects didnt work continuously.My class had no more function,and only overrided the OnReceive.I wondered whether there exits some method to find the problem. The server program is written with c++ builder,and if I use c++ builder and its socket controls,I have no problem in receiving and saving data.But I dont know why it failed in VC++ 2005. I hope your help,thanx.
modified on Sunday, December 5, 2010 11:34 PM
-
Hi everybody: I am greenhand in socket programming. I want to write a little program to receive tcp data and save them from server with multi port(almost 64 ports),the data was in deferent data rate.I read msdn and decided to use CAsyncSocket.I wrote a simple class CMySocket,and overide the OnReceive function.In the function,I want to save the received data to file. When I used the new class,I created 64 CMySocket objects,and connect to the server ports.They connected the server well,and OnReceive function was triggered.But after some seconds,for example 10 seconds or handreds seconds,some objects' OnReceive was never triggered any longer,at last all objects were still ,no data incomed. I have no idea why my objects didnt work continuously.My class had no more function,and only overrided the OnReceive.I wondered whether there exits some method to find the problem. The server program is written with c++ builder,and if I use c++ builder and its socket controls,I have no problem in receiving and saving data.But I dont know why it failed in VC++ 2005. I hope your help,thanx.
modified on Sunday, December 5, 2010 11:34 PM
Hi Stephen, You have not shown any code so its practically impossible to determine what is causing you grief. All I can recommend at this point is that you learn how to use the visual studio 2005 debugger[^]. It is not as difficult as it seems. My guess is that your application is generating a socket error. You should add a breakpoint in the OnReceive, OnClose and Shutdown functions and check for failures. I would also recommend that you learn how to use a packet sniffer such as Wireshark[^]. Thanks all I can think of for now. Good Luck, -David Delaune
-
Hi Stephen, You have not shown any code so its practically impossible to determine what is causing you grief. All I can recommend at this point is that you learn how to use the visual studio 2005 debugger[^]. It is not as difficult as it seems. My guess is that your application is generating a socket error. You should add a breakpoint in the OnReceive, OnClose and Shutdown functions and check for failures. I would also recommend that you learn how to use a packet sniffer such as Wireshark[^]. Thanks all I can think of for now. Good Luck, -David Delaune
Thanx for your reply!I will try it.
-
Hi everybody: I am greenhand in socket programming. I want to write a little program to receive tcp data and save them from server with multi port(almost 64 ports),the data was in deferent data rate.I read msdn and decided to use CAsyncSocket.I wrote a simple class CMySocket,and overide the OnReceive function.In the function,I want to save the received data to file. When I used the new class,I created 64 CMySocket objects,and connect to the server ports.They connected the server well,and OnReceive function was triggered.But after some seconds,for example 10 seconds or handreds seconds,some objects' OnReceive was never triggered any longer,at last all objects were still ,no data incomed. I have no idea why my objects didnt work continuously.My class had no more function,and only overrided the OnReceive.I wondered whether there exits some method to find the problem. The server program is written with c++ builder,and if I use c++ builder and its socket controls,I have no problem in receiving and saving data.But I dont know why it failed in VC++ 2005. I hope your help,thanx.
modified on Sunday, December 5, 2010 11:34 PM
Hi,I found the reason. In OnReceive,I used a fixed length buffer to call Receive function,But in fact,sometimes the incoming data's length is great than the buffer length.So there was some data remained in system buffer,and the app didnt get them,I think it made OnReceive not be called anymore. Thanx everybody's advice!!