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 recv on tcp socket

timeout recv on tcp socket

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestion
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.
  • O Offline
    O Offline
    orcun colak
    wrote on last edited by
    #1

    I have a TCP socket. After connecing to the server I would like to recv data but recv is blocking. I would like to timeout after 5 seconds if server does not respond. How can I timeout the recv call.:( Thanks

    G A 2 Replies Last reply
    0
    • O orcun colak

      I have a TCP socket. After connecing to the server I would like to recv data but recv is blocking. I would like to timeout after 5 seconds if server does not respond. How can I timeout the recv call.:( Thanks

      G Offline
      G Offline
      geo_m
      wrote on last edited by
      #2

      hmm using the asyncsockets usually, but I believe that int timeout = SOME_VALUE_IN_MILLISEC; // 5000 in your case (5sec) setsockopt( sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout) ); can help you. Look to the documentation. (valid only for Microsofts Winsock2)

      1 Reply Last reply
      0
      • O orcun colak

        I have a TCP socket. After connecing to the server I would like to recv data but recv is blocking. I would like to timeout after 5 seconds if server does not respond. How can I timeout the recv call.:( Thanks

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Use something like WSAselect, or any of the other socket functions that allow you to wait on a socket for data. The benefit is that as well as waiting on the socket, you can also wait for other events in your program

        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