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. timeout problem

timeout problem

Scheduled Pinned Locked Moved C / C++ / MFC
help
3 Posts 3 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
    ALLERSLIT
    wrote on last edited by
    #1

    Hey, this is my code:

    connect(s, (SOCKADDR\*) &addrin, sizeof(addrin));
    
    send(s, stRequest.c\_str(), stRequest.length(), 0);
    cout << "stRequest sent." << endl;
    recv(s, buffer, sizeof(buffer), 0);
    cout << "buffer received." << endl;
    

    Now this works perfectly fine if the webserver is working well, but sometimes it just sits there trying to recv() forever.. Iam not exactly sure what causes it but either way, I need a way to set a timeout or something similiar.. I couldn't really find something helpfull on google, so yea I thought maybe you guys could help me out.

    _ M 2 Replies Last reply
    0
    • A ALLERSLIT

      Hey, this is my code:

      connect(s, (SOCKADDR\*) &addrin, sizeof(addrin));
      
      send(s, stRequest.c\_str(), stRequest.length(), 0);
      cout << "stRequest sent." << endl;
      recv(s, buffer, sizeof(buffer), 0);
      cout << "buffer received." << endl;
      

      Now this works perfectly fine if the webserver is working well, but sometimes it just sits there trying to recv() forever.. Iam not exactly sure what causes it but either way, I need a way to set a timeout or something similiar.. I couldn't really find something helpfull on google, so yea I thought maybe you guys could help me out.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You can use WSARecv or an overlapped socket. http://support.microsoft.com/kb/181611[^]

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      1 Reply Last reply
      0
      • A ALLERSLIT

        Hey, this is my code:

        connect(s, (SOCKADDR\*) &addrin, sizeof(addrin));
        
        send(s, stRequest.c\_str(), stRequest.length(), 0);
        cout << "stRequest sent." << endl;
        recv(s, buffer, sizeof(buffer), 0);
        cout << "buffer received." << endl;
        

        Now this works perfectly fine if the webserver is working well, but sometimes it just sits there trying to recv() forever.. Iam not exactly sure what causes it but either way, I need a way to set a timeout or something similiar.. I couldn't really find something helpfull on google, so yea I thought maybe you guys could help me out.

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

        ALLERSLIT wrote:

        Now this works perfectly fine if the webserver is working well, but sometimes it just sits there trying to recv() forever.. Iam not exactly sure what causes it but either way, I need a way to set a timeout or something similiar..

        There are multiple choices: - adjust the send/receive timeouts with setsockopt(), see SO_SNDTIMEO and SO_RCVTIMEO
        - use non-blocking/asynchronous sockets, makes event based applications so much easier - use a C++ networking library/API offering timeouts or search for a HTTP client class, would be my recommendation
        Happy coding! :)

        Chat in Europe :java: Now with 24% more Twitter

        modified on Friday, November 19, 2010 8:40 PM

        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