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. Windows sockets

Windows sockets

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiontutorial
4 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.
  • M Offline
    M Offline
    mweiss
    wrote on last edited by
    #1

    This is probably a very basic question, so bear with me :) I'm writing a console program and need to use asynchronous sockets. I wish to use WSAAsynchSelect(). The second parameter is a HWND to the window you want to handle the messages. The third parameter is the message you want handled. The events are specified in the fourth parameter. What I thought I could do was use a message loop, like while( bRet = GetMessage( &msg, NULL, 0, 0 ) != 0 ) { if( bRet == -1 ) { // handle } TranslateMessage( &msg ); DispatchMessage( &msg ); } and have the WinProc handle the message specified in WSAAsynchSelect(). The problem I'm having is that I get an "Invalid Argument" error (runtime) when WSAAsynchSelect() is called and I think it's because I'm sending a NULL instead of a valid HWND. My question is, does anyone know have advice how to use WSAAsynchSelect() in a console application? Thanks! mweiss

    G 1 Reply Last reply
    0
    • M mweiss

      This is probably a very basic question, so bear with me :) I'm writing a console program and need to use asynchronous sockets. I wish to use WSAAsynchSelect(). The second parameter is a HWND to the window you want to handle the messages. The third parameter is the message you want handled. The events are specified in the fourth parameter. What I thought I could do was use a message loop, like while( bRet = GetMessage( &msg, NULL, 0, 0 ) != 0 ) { if( bRet == -1 ) { // handle } TranslateMessage( &msg ); DispatchMessage( &msg ); } and have the WinProc handle the message specified in WSAAsynchSelect(). The problem I'm having is that I get an "Invalid Argument" error (runtime) when WSAAsynchSelect() is called and I think it's because I'm sending a NULL instead of a valid HWND. My question is, does anyone know have advice how to use WSAAsynchSelect() in a console application? Thanks! mweiss

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

      I guess you need to create some window to receive the messages - even in console app you can create windows - best choice will be some invisible - message only window (parent is HWND_MESSAGE). Then you'll have all - valid HWND, valid MsgProc for that window etc. Hope this helps

      M 1 Reply Last reply
      0
      • G geo_m

        I guess you need to create some window to receive the messages - even in console app you can create windows - best choice will be some invisible - message only window (parent is HWND_MESSAGE). Then you'll have all - valid HWND, valid MsgProc for that window etc. Hope this helps

        M Offline
        M Offline
        mweiss
        wrote on last edited by
        #3

        Thanks for the reply. I found a way to do it without using the windows. I use WSAEventSelect(), WSAWaitForMultipleEvents() and WSAEnumNetworkEvents(). I set up the events in the main thread and in a worker thread wait for events to occur, check which event it was and handle it. I haven't tested it yet, tho. Thanks. melinda

        G 1 Reply Last reply
        0
        • M mweiss

          Thanks for the reply. I found a way to do it without using the windows. I use WSAEventSelect(), WSAWaitForMultipleEvents() and WSAEnumNetworkEvents(). I set up the events in the main thread and in a worker thread wait for events to occur, check which event it was and handle it. I haven't tested it yet, tho. Thanks. melinda

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

          Yes, that's the better method, but you stated that you wish to use the before method, and I prefer to respect ppl. wishes ;-) Anyway, this is much better what you do now, the messaging part (window) is useful only when you have to handle the winsock 1. Only disadvantage is that you have two threads - mean the whole design is more complicated due to resource locking etc. I usualy trying to design it that it uses only one thread for all that tasks. But it really depends on the application, so there cannot be a general advice except that I said. wish you good luck!

          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