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. Other Discussions
  3. Article Writing
  4. To all you socket veterans out there

To all you socket veterans out there

Scheduled Pinned Locked Moved Article Writing
c++sysadmin
3 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Can someone please tell me a tried and true method for listing (from a client app, not a server) to a socket without hanging the entire program. I'm trying to detect when data arrives without having to continually probe the socket and without locking up the main app by blocking. There's CAsyncSocket & CSocket (MFC) that uses messaging, there's raw sockets, I guess I could create a new thread that performs a while loop and blocks on the call to recv(...) - should I use non-blocking I/O schemes - should I use winsock or winsock2, ... I'm a little overwhelmed and maybe I've made it harder than it should be. Any clarification is much appreciated. :confused: X|

    L D 2 Replies Last reply
    0
    • L Lost User

      Can someone please tell me a tried and true method for listing (from a client app, not a server) to a socket without hanging the entire program. I'm trying to detect when data arrives without having to continually probe the socket and without locking up the main app by blocking. There's CAsyncSocket & CSocket (MFC) that uses messaging, there's raw sockets, I guess I could create a new thread that performs a while loop and blocks on the call to recv(...) - should I use non-blocking I/O schemes - should I use winsock or winsock2, ... I'm a little overwhelmed and maybe I've made it harder than it should be. Any clarification is much appreciated. :confused: X|

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

      I use this way: I usually use the data I expect to come. When the error occurs - there are no new data. When not - that is OK. This works! ;)

      1 Reply Last reply
      0
      • L Lost User

        Can someone please tell me a tried and true method for listing (from a client app, not a server) to a socket without hanging the entire program. I'm trying to detect when data arrives without having to continually probe the socket and without locking up the main app by blocking. There's CAsyncSocket & CSocket (MFC) that uses messaging, there's raw sockets, I guess I could create a new thread that performs a while loop and blocks on the call to recv(...) - should I use non-blocking I/O schemes - should I use winsock or winsock2, ... I'm a little overwhelmed and maybe I've made it harder than it should be. Any clarification is much appreciated. :confused: X|

        D Offline
        D Offline
        Dark Angel
        wrote on last edited by
        #3

        If your starting out, I'd just use the MFC CSocket class. Get a simple client and server working with CSocket and then get complicated (i.e. asychronous) later. Override the OnReceive(...) message. When data shows up, OnReceive will get called, so then you call Receive(...) to receive the data. If there is more data in the buffer, OnReceive will get called again for you. I don't know if the socket calls are blocking or not, but CSocket works synchronously rather than asynchronously, which will save you a lot of headaches. In my experience, the CSocket Connect() call is annoying when it blocks, but the Receive() and Send() calls are barely noticable when you call them. Remember that we're going at network speed, dude, and we know that the data has already arrived via TCP/IP. All you have to do is read it out of memory. "Harland Pepper, would you stop naming nuts" - Harland Pepper

        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