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. Re-using a socket after a completed AcceptEx() call!

Re-using a socket after a completed AcceptEx() call!

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

    Hello, I have a little problem on re-using a socket after a completed AcceptEx call. The number of maximum clients is equal to the number of sockets in my program. On every socket I made an AcceptEx() call to accept a new connection and receive the data. So far so good. After receiving the data I need a new AcceptEx() call which can receive data from other clients who are trying to connect. But - something is going wrong! When I simply recall AcceptEx() on the same listener socket and the same accept socket I get an error (WSAEINVAL / 10022L). Do I have to close the socket before I try to make a new AcceptEx() call on that socket? I would like to re-use this socket and leave it open, because it's queued in a completion port. I hope you can help me. Thanks for your attention! bond006

    V G 2 Replies Last reply
    0
    • B bond006

      Hello, I have a little problem on re-using a socket after a completed AcceptEx call. The number of maximum clients is equal to the number of sockets in my program. On every socket I made an AcceptEx() call to accept a new connection and receive the data. So far so good. After receiving the data I need a new AcceptEx() call which can receive data from other clients who are trying to connect. But - something is going wrong! When I simply recall AcceptEx() on the same listener socket and the same accept socket I get an error (WSAEINVAL / 10022L). Do I have to close the socket before I try to make a new AcceptEx() call on that socket? I would like to re-use this socket and leave it open, because it's queued in a completion port. I hope you can help me. Thanks for your attention! bond006

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      Yes, you must close the socket before assigning a new socket to that same variable. Kuphryn

      B 1 Reply Last reply
      0
      • V valikac

        Yes, you must close the socket before assigning a new socket to that same variable. Kuphryn

        B Offline
        B Offline
        bond006
        wrote on last edited by
        #3

        Which socket? The listener socket or the accept socket? ;) When I close the listener socket I have no sockets at all! :) bond006

        1 Reply Last reply
        0
        • B bond006

          Hello, I have a little problem on re-using a socket after a completed AcceptEx call. The number of maximum clients is equal to the number of sockets in my program. On every socket I made an AcceptEx() call to accept a new connection and receive the data. So far so good. After receiving the data I need a new AcceptEx() call which can receive data from other clients who are trying to connect. But - something is going wrong! When I simply recall AcceptEx() on the same listener socket and the same accept socket I get an error (WSAEINVAL / 10022L). Do I have to close the socket before I try to make a new AcceptEx() call on that socket? I would like to re-use this socket and leave it open, because it's queued in a completion port. I hope you can help me. Thanks for your attention! bond006

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

          Hi, well, you have two possibilities - first is to close the socket before you use the new AcceptEx using the closesocket(). But then you simply destroyed everything and there's no reuse. Second is to re-use the socket - for this you can use this trick: Instead of calling closesocket() you can use this one: TransmitFile( sock, NULL, 0, 0, NULL, NULL, TF_DISCONNECT | TF_REUSE_SOCKET ) This will close the socket, but makes it ready for AcceptEx reuse. Works only on NT, but as you wrote you use IOCP, so should not be a problem here ;)

          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