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#
  4. A silly socket question

A silly socket question

Scheduled Pinned Locked Moved C#
questionsysadmin
3 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.
  • S Offline
    S Offline
    sameerhanda
    wrote on last edited by
    #1

    Ok I have a server that is listening for incoming requests on ports 9000 through 9010. That being said, here is the quandry I have. If two people happen to grab port 9005, would the first person to get there lock it down. I mean if the second person gets there at the same time how can I direct the client app to try to reconnect on an other port. Any ideas or sample code would be welcome.

    S S 2 Replies Last reply
    0
    • S sameerhanda

      Ok I have a server that is listening for incoming requests on ports 9000 through 9010. That being said, here is the quandry I have. If two people happen to grab port 9005, would the first person to get there lock it down. I mean if the second person gets there at the same time how can I direct the client app to try to reconnect on an other port. Any ideas or sample code would be welcome.

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      Only one socket can listen on a particular port. But more than one socket can connect to a single port. From your question, it is not clear whether you meant the first or the second. In the first case, the call to Listen() will fail with an exception. Regards Senthil My Blog

      1 Reply Last reply
      0
      • S sameerhanda

        Ok I have a server that is listening for incoming requests on ports 9000 through 9010. That being said, here is the quandry I have. If two people happen to grab port 9005, would the first person to get there lock it down. I mean if the second person gets there at the same time how can I direct the client app to try to reconnect on an other port. Any ideas or sample code would be welcome.

        S Offline
        S Offline
        Sebastian Schneider
        wrote on last edited by
        #3

        Try reading on "non-blocking server socket" in the MSDN. The thing is: if you have a "server loop" which waits on data to arrive on any of these ports, then does some manipulation and loops, you will always have poor performance, as your application will block until you are done with one of the requests. If you decided to use 10 ports in order to offer "10 parallel connections", you totally misunderstood the concept (sorry :)). You should only use different ports for different services (e.g. FTP Control connection on Port 21, HTTP on Port 80, ...) or to seperate user-groups (e.g. Customer1 connects to FTP on port 21, Customer2 uses Port 23, ...). Specifically, you might want to read into Delegates, Callbacks, etc. These are, IMHO, the easiest way to create socket-using apps without doing manual multithreading. Cheers Sid

        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