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. Question about using CSocket writing a server

Question about using CSocket writing a server

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

    Hello, I wonder what is the usage of using Bind method after creating a CSocket in the server. I get an error message when I Bind the socket, however, if I ignore the error, I can still receive the message come from the client. So, what is the usage of using Bind method in server side? Actually, my code is something like this, rt = cs.Create(1000, SOCK_STREAM, "127.0.0.1"); if (rt == 0) Print_Error(); rt = cs.Bind(1000, "127.0.0.1"); if (rt == 0) Print_Error(); When the program is going to bind the socket, it return error message 10022, which the documentation told me that is "invalid argument" exception. Can someone told me what is my problem? Thanks! Nachi:(

    J 1 Reply Last reply
    0
    • N nachilau

      Hello, I wonder what is the usage of using Bind method after creating a CSocket in the server. I get an error message when I Bind the socket, however, if I ignore the error, I can still receive the message come from the client. So, what is the usage of using Bind method in server side? Actually, my code is something like this, rt = cs.Create(1000, SOCK_STREAM, "127.0.0.1"); if (rt == 0) Print_Error(); rt = cs.Bind(1000, "127.0.0.1"); if (rt == 0) Print_Error(); When the program is going to bind the socket, it return error message 10022, which the documentation told me that is "invalid argument" exception. Can someone told me what is my problem? Thanks! Nachi:(

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      You are already binding the socket in the constructor, so the extra call to Bind is superfluous. I guess you are misinterpreting the error code (this should be retrieved with WSAGetLastError and looked upon in the Winsock error table provided by the documentation. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      N 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        You are already binding the socket in the constructor, so the extra call to Bind is superfluous. I guess you are misinterpreting the error code (this should be retrieved with WSAGetLastError and looked upon in the Winsock error table provided by the documentation. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        N Offline
        N Offline
        nachilau
        wrote on last edited by
        #3

        So, you mean by just do this, rt = cs.Create(1000, SOCK_STREAM, "127.0.0.1"); I have already bind the socket?? Thanks! Nachi

        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