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. CSocket Bind Invalid Argument Error

CSocket Bind Invalid Argument Error

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

    I am trying to create a UDP connection using the CSocket class. The code I have so far is this: CSocket sock; //Create socket if (!sock.Create(0, SOCK_DGRAM, NULL)) { GetSocketError(); //Get Socket's Last Error return -1; } //__if (!sock.Create(...))__ //Bind socket if(!sock.Bind((UINT)4200, _T("127.0.0.1"))) { GetSocketError(); //Get Socket's Last Error return -1; } //__if(sock.Bind(...))__ The call to Create() works without a problem but when I try to bind to the port and address I get an "Invalid Argument (10022)" error. Any suggestions? Thanks.

    K R 2 Replies Last reply
    0
    • M masnu

      I am trying to create a UDP connection using the CSocket class. The code I have so far is this: CSocket sock; //Create socket if (!sock.Create(0, SOCK_DGRAM, NULL)) { GetSocketError(); //Get Socket's Last Error return -1; } //__if (!sock.Create(...))__ //Bind socket if(!sock.Bind((UINT)4200, _T("127.0.0.1"))) { GetSocketError(); //Get Socket's Last Error return -1; } //__if(sock.Bind(...))__ The call to Create() works without a problem but when I try to bind to the port and address I get an "Invalid Argument (10022)" error. Any suggestions? Thanks.

      K Offline
      K Offline
      Kiran Pinjala
      wrote on last edited by
      #2

      Did u see what does error 10022 mean?

      KIRAN PINJARLA

      M 1 Reply Last reply
      0
      • K Kiran Pinjala

        Did u see what does error 10022 mean?

        KIRAN PINJARLA

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

        Yes... it's an "Invalid Argument" error: WSAEINVAL (10022) Invalid argument. Some invalid argument was supplied (for example, specifying an invalid level to the setsockopt function). In some instances, it also refers to the current state of the socket - for instance, calling accept on a socket that is not listening.

        1 Reply Last reply
        0
        • M masnu

          I am trying to create a UDP connection using the CSocket class. The code I have so far is this: CSocket sock; //Create socket if (!sock.Create(0, SOCK_DGRAM, NULL)) { GetSocketError(); //Get Socket's Last Error return -1; } //__if (!sock.Create(...))__ //Bind socket if(!sock.Bind((UINT)4200, _T("127.0.0.1"))) { GetSocketError(); //Get Socket's Last Error return -1; } //__if(sock.Bind(...))__ The call to Create() works without a problem but when I try to bind to the port and address I get an "Invalid Argument (10022)" error. Any suggestions? Thanks.

          R Offline
          R Offline
          Raj Prathap
          wrote on last edited by
          #4

          masnu wrote:

          if(!sock.Bind((UINT)4200, _T("127.0.0.1")))

          why dont you try with NULL as the second parameter?

          M 1 Reply Last reply
          0
          • R Raj Prathap

            masnu wrote:

            if(!sock.Bind((UINT)4200, _T("127.0.0.1")))

            why dont you try with NULL as the second parameter?

            M Offline
            M Offline
            masnu
            wrote on last edited by
            #5

            I did. Same error occurs.

            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