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. Visual Basic
  4. Multiple Socket Connection

Multiple Socket Connection

Scheduled Pinned Locked Moved Visual Basic
questioncsharphtmlcom
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.
  • M Offline
    M Offline
    MatthysDT
    wrote on last edited by
    #1

    How do I create a server socket which can accept multiple connection on the same port? Just about every source I found on the internet explains that a Socket-array is used to do this, but that doesn't make sense to me. Even if I use a socket array, if mySocket(1) listens on port 9700, mySocket(2) cannot listen on that same port since the "address is already in use". I've read sources explaining that the socket should be "moved off" to another port after the initial connection, which means that the host should reply to the incoming connection with a new port number... is there a standard global way of doing this? Example... I can VNC my PC over the internet from two different VNC clients at the same time i.e on the same port, how does that server accept more than one connection? "Moving the port off" doesn't seem like a viable solution since the router only has one port forwarding entry on a single port, yet it work fine for multiple connections... but how does this work? The application I am tasked to upgrade is a VB6 application, hence I'm using Winsock, but help in .Net is just as fine, I'm more after the principal than the actual code. Kind Regards

    Doggy treat[^]

    O S 2 Replies Last reply
    0
    • M MatthysDT

      How do I create a server socket which can accept multiple connection on the same port? Just about every source I found on the internet explains that a Socket-array is used to do this, but that doesn't make sense to me. Even if I use a socket array, if mySocket(1) listens on port 9700, mySocket(2) cannot listen on that same port since the "address is already in use". I've read sources explaining that the socket should be "moved off" to another port after the initial connection, which means that the host should reply to the incoming connection with a new port number... is there a standard global way of doing this? Example... I can VNC my PC over the internet from two different VNC clients at the same time i.e on the same port, how does that server accept more than one connection? "Moving the port off" doesn't seem like a viable solution since the router only has one port forwarding entry on a single port, yet it work fine for multiple connections... but how does this work? The application I am tasked to upgrade is a VB6 application, hence I'm using Winsock, but help in .Net is just as fine, I'm more after the principal than the actual code. Kind Regards

      Doggy treat[^]

      O Offline
      O Offline
      Oktay1
      wrote on last edited by
      #2

      You must Listen to incomming requests on a different thread and create a new thread to accept the socket and pass the socket reference to created thread. After that your listener can accept other incoming requests.

      1 Reply Last reply
      0
      • M MatthysDT

        How do I create a server socket which can accept multiple connection on the same port? Just about every source I found on the internet explains that a Socket-array is used to do this, but that doesn't make sense to me. Even if I use a socket array, if mySocket(1) listens on port 9700, mySocket(2) cannot listen on that same port since the "address is already in use". I've read sources explaining that the socket should be "moved off" to another port after the initial connection, which means that the host should reply to the incoming connection with a new port number... is there a standard global way of doing this? Example... I can VNC my PC over the internet from two different VNC clients at the same time i.e on the same port, how does that server accept more than one connection? "Moving the port off" doesn't seem like a viable solution since the router only has one port forwarding entry on a single port, yet it work fine for multiple connections... but how does this work? The application I am tasked to upgrade is a VB6 application, hence I'm using Winsock, but help in .Net is just as fine, I'm more after the principal than the actual code. Kind Regards

        Doggy treat[^]

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

        evilnoodle wrote:

        How do I create a server socket which can accept multiple connection on the same port?

        When a socket is 'listening' and someone connects, the .Accept() method of that socket will return a new socket which is 'talking' to whoever called in. Once that has been done, the 'listening' socket can accept another connection. When that connection comes in, .Accept() will return a different socket which can exchange data with the new caller. After a connection is handed off to a new socket with .Accept(), the original listening socket will no longer "care" about it. There are practical limits to how many sockets can be connected at once, but if one creates a new thread for each socket it's pretty easy to handle quite a few. Note that starting a new thread for each socket isn't strictly necessary, but it's often the easiest way to do things. The biggest 'gotcha' is that the new threads won't be able to interact with the UI directly.

        M 1 Reply Last reply
        0
        • S supercat9

          evilnoodle wrote:

          How do I create a server socket which can accept multiple connection on the same port?

          When a socket is 'listening' and someone connects, the .Accept() method of that socket will return a new socket which is 'talking' to whoever called in. Once that has been done, the 'listening' socket can accept another connection. When that connection comes in, .Accept() will return a different socket which can exchange data with the new caller. After a connection is handed off to a new socket with .Accept(), the original listening socket will no longer "care" about it. There are practical limits to how many sockets can be connected at once, but if one creates a new thread for each socket it's pretty easy to handle quite a few. Note that starting a new thread for each socket isn't strictly necessary, but it's often the easiest way to do things. The biggest 'gotcha' is that the new threads won't be able to interact with the UI directly.

          M Offline
          M Offline
          MatthysDT
          wrote on last edited by
          #4

          Thank you, this will really help!

          Doggy treat[^]

          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