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. Winsock - FD_WRITE

Winsock - FD_WRITE

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

    Hi all, i am developing client program using WSAAsyncselect() in Winsock2. i have few queries regarding FD_WRITE. i understood that when client is connected to server. There will be FD_WRITE event posted stating that we can send the data to server. However, i want to send data to server based on some other events that the application is interested in. i am not quite sure how the FD_WRITE event will be fired when i want send data to server. here is the pseudo.

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message)
    {
    case WM_SOMEOTHEREVENT:
    // collect the data. we need to send collected data to sever (right now data is stored in a list).
    break;
    case WM_SOCKET:
    switch (WSAGETSELECTEVENT(lParam))
    {
    // how to fire this event when application wants to send data ?
    case FD_WRITE:

    	     break;
    	}
    	break;
    }
    return 0;
    

    }

    Thanks in advance.

    D U 2 Replies Last reply
    0
    • V Vijjuuu

      Hi all, i am developing client program using WSAAsyncselect() in Winsock2. i have few queries regarding FD_WRITE. i understood that when client is connected to server. There will be FD_WRITE event posted stating that we can send the data to server. However, i want to send data to server based on some other events that the application is interested in. i am not quite sure how the FD_WRITE event will be fired when i want send data to server. here is the pseudo.

      LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
      {
      switch (message)
      {
      case WM_SOMEOTHEREVENT:
      // collect the data. we need to send collected data to sever (right now data is stored in a list).
      break;
      case WM_SOCKET:
      switch (WSAGETSELECTEVENT(lParam))
      {
      // how to fire this event when application wants to send data ?
      case FD_WRITE:

      	     break;
      	}
      	break;
      }
      return 0;
      

      }

      Thanks in advance.

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

      Your application will receive an FD_WRITE event shortly after a connection is made. If your "write" operation receives a WSAEWOULDBLOCK result, your application will find out that sends are again possible when an FD_WRITE network event is recorded and the associated event object is set.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      V 1 Reply Last reply
      0
      • D David Crow

        Your application will receive an FD_WRITE event shortly after a connection is made. If your "write" operation receives a WSAEWOULDBLOCK result, your application will find out that sends are again possible when an FD_WRITE network event is recorded and the associated event object is set.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        V Offline
        V Offline
        Vijjuuu
        wrote on last edited by
        #3

        Hi David, Thanks for your reply. i am sorry, i couldn't get what you mean. i understand that application will receive an FD_WRITE event shortly after a connection is made but there is no data to send at that time. here is scenario i am trying for 1) connect to server 2) Connection established - FD_WRITE event is receive. 3) there is no data to send to server 4) some other event fired (not related to socket) -- data arrived, so store the data. 5) now data is available to send to server in the above steps 4 and 5 will happen one after the another. how can i raise FD_Write event after the data is available (means step 4) ?

        D 1 Reply Last reply
        0
        • V Vijjuuu

          Hi David, Thanks for your reply. i am sorry, i couldn't get what you mean. i understand that application will receive an FD_WRITE event shortly after a connection is made but there is no data to send at that time. here is scenario i am trying for 1) connect to server 2) Connection established - FD_WRITE event is receive. 3) there is no data to send to server 4) some other event fired (not related to socket) -- data arrived, so store the data. 5) now data is available to send to server in the above steps 4 and 5 will happen one after the another. how can i raise FD_Write event after the data is available (means step 4) ?

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

          Vijjuuu. wrote:

          how can i raise FD_Write event after the data is available (means step 4) ?

          Why would you need to raise the FD_WRITE event? It is sent to your application to let it know that it can now send data to the socket.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          V 1 Reply Last reply
          0
          • D David Crow

            Vijjuuu. wrote:

            how can i raise FD_Write event after the data is available (means step 4) ?

            Why would you need to raise the FD_WRITE event? It is sent to your application to let it know that it can now send data to the socket.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            V Offline
            V Offline
            Vijjuuu
            wrote on last edited by
            #5

            Thanks again David, i understood that its lets application know that it can send data to the socket, but when there is no data to send ? and does it mean after initial FD_Write (the time after connection established) , FD_WRITE will be polled to application to let know that it can send data ? i really appreciate your patience. Thanks.

            D 1 Reply Last reply
            0
            • V Vijjuuu

              Thanks again David, i understood that its lets application know that it can send data to the socket, but when there is no data to send ? and does it mean after initial FD_Write (the time after connection established) , FD_WRITE will be polled to application to let know that it can send data ? i really appreciate your patience. Thanks.

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

              Vijjuuu. wrote:

              ...but when there is no data to send ?

              Then don't send any.

              Vijjuuu. wrote:

              and does it mean after initial FD_Write (the time after connection established) , FD_WRITE will be polled to application to let know that it can send data ?

              Did you read the documentation that goes with that event? Your application gets the initial FD_WRITE event which means it can start sending data to the socket. In the event that whatever "send" function you are using returns WSAEWOULDBLOCK, you would then have to wait for the next FD_WRITE event to resume sending data to the socket.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              1 Reply Last reply
              0
              • V Vijjuuu

                Hi all, i am developing client program using WSAAsyncselect() in Winsock2. i have few queries regarding FD_WRITE. i understood that when client is connected to server. There will be FD_WRITE event posted stating that we can send the data to server. However, i want to send data to server based on some other events that the application is interested in. i am not quite sure how the FD_WRITE event will be fired when i want send data to server. here is the pseudo.

                LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                {
                switch (message)
                {
                case WM_SOMEOTHEREVENT:
                // collect the data. we need to send collected data to sever (right now data is stored in a list).
                break;
                case WM_SOCKET:
                switch (WSAGETSELECTEVENT(lParam))
                {
                // how to fire this event when application wants to send data ?
                case FD_WRITE:

                	     break;
                	}
                	break;
                }
                return 0;
                

                }

                Thanks in advance.

                U Offline
                U Offline
                User 12573126
                wrote on last edited by
                #7

                As I understand it, the FD_WRITE message means you have a connection and room in the output buffer to accept data. After you get FD_WRITE, use send() to send data when you have it.

                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