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. Socket ptogramming

Socket ptogramming

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 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
    Amjath Rahman
    wrote on last edited by
    #1

    Hi All, Im implementing socket in my application. its working fine, but my problem is i want to attach a thread for socket receive. how can i implement this, plz help me out... im using CAsyncSocket. its a dialog based application. With Regards Amjath

    L 1 Reply Last reply
    0
    • A Amjath Rahman

      Hi All, Im implementing socket in my application. its working fine, but my problem is i want to attach a thread for socket receive. how can i implement this, plz help me out... im using CAsyncSocket. its a dialog based application. With Regards Amjath

      L Offline
      L Offline
      Llasus
      wrote on last edited by
      #2

      Do you mean that you want to pass the socket to a thread for receiving? You can do that by using the thread's parameter and pass the socket variable to it.

      A 1 Reply Last reply
      0
      • L Llasus

        Do you mean that you want to pass the socket to a thread for receiving? You can do that by using the thread's parameter and pass the socket variable to it.

        A Offline
        A Offline
        Amjath Rahman
        wrote on last edited by
        #3

        First of all thanks for ur reply...... if possible plz help me through some sample code.......... can u plz do this needful help... With regards Amjath

        L 1 Reply Last reply
        0
        • A Amjath Rahman

          First of all thanks for ur reply...... if possible plz help me through some sample code.......... can u plz do this needful help... With regards Amjath

          L Offline
          L Offline
          Llasus
          wrote on last edited by
          #4

          Here's a somewhat sample code to pass the SOCKET to a thread. Hope this helps. CAsyncSocket ListenSocket; //global socket variable, declare this in the header file BOOL CClassSample::Initialize() { //initialize the pipe variable //create the thread HListenThread = CreateThread(NULL, 0, &ListenThread, (LPVOID)&ListenSocket, 0, &ListenThreadID ); //Error handling for CreateThread if (HListenThread == NULL || HListenThread == INVALID_HANDLE_VALUE) { return FALSE; } } DWORD WINAPI CClassSample::ListenThread(LPVOID lpParameter) { //assign the parameter to the SOCKET variable CAsyncSocket *pListenSocket = (CAsyncSocket*)lpParameter; //some processing here }

          A 1 Reply Last reply
          0
          • L Llasus

            Here's a somewhat sample code to pass the SOCKET to a thread. Hope this helps. CAsyncSocket ListenSocket; //global socket variable, declare this in the header file BOOL CClassSample::Initialize() { //initialize the pipe variable //create the thread HListenThread = CreateThread(NULL, 0, &ListenThread, (LPVOID)&ListenSocket, 0, &ListenThreadID ); //Error handling for CreateThread if (HListenThread == NULL || HListenThread == INVALID_HANDLE_VALUE) { return FALSE; } } DWORD WINAPI CClassSample::ListenThread(LPVOID lpParameter) { //assign the parameter to the SOCKET variable CAsyncSocket *pListenSocket = (CAsyncSocket*)lpParameter; //some processing here }

            A Offline
            A Offline
            Amjath Rahman
            wrote on last edited by
            #5

            Thank u very much dude im new to vc++, sorry for asking such a small question from where v can get this variable buddy "ListenThreadID"

            D L 2 Replies Last reply
            0
            • A Amjath Rahman

              Thank u very much dude im new to vc++, sorry for asking such a small question from where v can get this variable buddy "ListenThreadID"

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Amjath Rahman wrote:

              im new to vc++,

              So why are you trying to tackle a project that is not for beginners? Sockets or threads is a medium-difficulty project at best, but doing them in tandem is no trivial task.


              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              1 Reply Last reply
              0
              • A Amjath Rahman

                Thank u very much dude im new to vc++, sorry for asking such a small question from where v can get this variable buddy "ListenThreadID"

                L Offline
                L Offline
                Llasus
                wrote on last edited by
                #7

                Its a DWORD which holds the ID for the ListenThread.

                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