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. Sockets and multithreading - doubt

Sockets and multithreading - doubt

Scheduled Pinned Locked Moved C / C++ / MFC
designquestion
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.
  • R Offline
    R Offline
    Raj Prathap
    wrote on last edited by
    #1

    All, I have a doubt whether two different threads can be working on a same socket descriptor(handle in windows terminology)? Please go through the following scenario: We have one device which supports TCP/IP: 1. Responds to the requests 2. Sends notifications, incase any events Can I have two threads one for continuesly wait to receive the notifications & response and another for sending the requests to the panel? Could someone please provide (link will suffice)a good design for this class. Best Regards, Pratap

    L M 2 Replies Last reply
    0
    • R Raj Prathap

      All, I have a doubt whether two different threads can be working on a same socket descriptor(handle in windows terminology)? Please go through the following scenario: We have one device which supports TCP/IP: 1. Responds to the requests 2. Sends notifications, incase any events Can I have two threads one for continuesly wait to receive the notifications & response and another for sending the requests to the panel? Could someone please provide (link will suffice)a good design for this class. Best Regards, Pratap

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Raj Prathap wrote:

      Can I have two threads one for continuesly wait to receive the notifications & response and another for sending the requests

      You can read from the socket in one thread and write to the socket in a different thread. I think that is what you mean and Yes you can.

      1 Reply Last reply
      0
      • R Raj Prathap

        All, I have a doubt whether two different threads can be working on a same socket descriptor(handle in windows terminology)? Please go through the following scenario: We have one device which supports TCP/IP: 1. Responds to the requests 2. Sends notifications, incase any events Can I have two threads one for continuesly wait to receive the notifications & response and another for sending the requests to the panel? Could someone please provide (link will suffice)a good design for this class. Best Regards, Pratap

        M Offline
        M Offline
        Matthew Faithfull
        wrote on last edited by
        #3

        Read with one thread and write with another is fine with one proviso. If you're unfortunate enough to be using MFC Sockets then don't pass the handles (Which are actaully Window Handles) between threads lest they suddenly and magically become invalid. It can be done but you'll need to root around in the MS Docs to find how to do it safely. If you're writing this sort of thing you might want to check out IO Completion Ports, a bit mind bending but they can make multithreaded socket apps a lot slicker. :)

        Nothing is exactly what it seems but everything with seems can be unpicked.

        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