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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Why connect() fails in the worker thread but succeeds in the main thread?

Why connect() fails in the worker thread but succeeds in the main thread?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
2 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.
  • W Offline
    W Offline
    Wenrich
    wrote on last edited by
    #1

    In my MFC application running on Win2k, the following code fails in a worker thread, but succeeds in the main thread. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ servaddr.sin_family = AF_INET; servaddr.sin_port = htons(PORT); servaddr.sin_addr.S_addr = IP; int ret = connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ In the worker thread, the error is always WSAETIMEDOUT, never succeeds! But the same code in an applicaiton running on WinCE works well! What's wrong with it? Thanks a lot!

    R 1 Reply Last reply
    0
    • W Wenrich

      In my MFC application running on Win2k, the following code fails in a worker thread, but succeeds in the main thread. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ servaddr.sin_family = AF_INET; servaddr.sin_port = htons(PORT); servaddr.sin_addr.S_addr = IP; int ret = connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ In the worker thread, the error is always WSAETIMEDOUT, never succeeds! But the same code in an applicaiton running on WinCE works well! What's wrong with it? Thanks a lot!

      R Offline
      R Offline
      RobJones
      wrote on last edited by
      #2

      I believe you need to use a UI type thread instead of a worker thread because the worker thread doesn't have a message pump.. Rob

      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