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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem about Socket

Problem about Socket

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

    I create a stream socket and start listening immediately. But when I use "netstat -a" command in the cmd window,the socket's port would not be shown in the list.The sample code only like below: CSocket listenSocket; if(listenSocket.Create(0,SOCK_STREAM)==TRUE) { SOCKET port=listenSocket.m_hSocket; if(listenSocket.Listen(10)==FALSE) cout<<"Listen Failed!"<

    M S 2 Replies Last reply
    0
    • K kcynic

      I create a stream socket and start listening immediately. But when I use "netstat -a" command in the cmd window,the socket's port would not be shown in the list.The sample code only like below: CSocket listenSocket; if(listenSocket.Create(0,SOCK_STREAM)==TRUE) { SOCKET port=listenSocket.m_hSocket; if(listenSocket.Listen(10)==FALSE) cout<<"Listen Failed!"<

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Is your listenSocket variable going out of scope? Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      K 1 Reply Last reply
      0
      • K kcynic

        I create a stream socket and start listening immediately. But when I use "netstat -a" command in the cmd window,the socket's port would not be shown in the list.The sample code only like below: CSocket listenSocket; if(listenSocket.Create(0,SOCK_STREAM)==TRUE) { SOCKET port=listenSocket.m_hSocket; if(listenSocket.Listen(10)==FALSE) cout<<"Listen Failed!"<

        S Offline
        S Offline
        Snnu
        wrote on last edited by
        #3

        because you use listenSocket.Create(0,SOCK_STREAM) create listen socket, "0" means the server listen port is random number. this random number is also shown in the "netstat -a" list. If you use listenSocket.Create(8000,SOCK_STREAM), the listen socket port will be fixed 8000. try "netstat -a" command you will find the listen port is 8000.

        K 1 Reply Last reply
        0
        • M Mark Salsbery

          Is your listenSocket variable going out of scope? Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          K Offline
          K Offline
          kcynic
          wrote on last edited by
          #4

          No,the socket is the member of the class

          1 Reply Last reply
          0
          • S Snnu

            because you use listenSocket.Create(0,SOCK_STREAM) create listen socket, "0" means the server listen port is random number. this random number is also shown in the "netstat -a" list. If you use listenSocket.Create(8000,SOCK_STREAM), the listen socket port will be fixed 8000. try "netstat -a" command you will find the listen port is 8000.

            K Offline
            K Offline
            kcynic
            wrote on last edited by
            #5

            But,if I change to Create() and listen,the problem remain so. Thanks

            M 1 Reply Last reply
            0
            • K kcynic

              But,if I change to Create() and listen,the problem remain so. Thanks

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              kcynic wrote:

              But,if I change to Create() and listen,the problem remain so.

              Try something like Create(2500, SOCK_STREAM) and see if there's a socket listening on port 2500. Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              K 1 Reply Last reply
              0
              • M Mark Salsbery

                kcynic wrote:

                But,if I change to Create() and listen,the problem remain so.

                Try something like Create(2500, SOCK_STREAM) and see if there's a socket listening on port 2500. Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                K Offline
                K Offline
                kcynic
                wrote on last edited by
                #7

                But my real work is to create a listen socket and report the listening port to others then other client can to connect to the listening socket. Thanks. 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