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. [Solved]My CAsyncSocket class doesn't receive data after some secondes. [modified]

[Solved]My CAsyncSocket class doesn't receive data after some secondes. [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++sysadmintutorial
4 Posts 2 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.
  • S Offline
    S Offline
    stephen_young
    wrote on last edited by
    #1

    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

    L S 2 Replies Last reply
    0
    • S stephen_young

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • L Lost User

        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

        S Offline
        S Offline
        stephen_young
        wrote on last edited by
        #3

        Thanx for your reply!I will try it.

        1 Reply Last reply
        0
        • S stephen_young

          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

          S Offline
          S Offline
          stephen_young
          wrote on last edited by
          #4

          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!!

          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