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. Handling multiple clients via Sockets

Handling multiple clients via Sockets

Scheduled Pinned Locked Moved C#
questionsysadminagentic-aitutorial
9 Posts 5 Posters 1 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.
  • J Offline
    J Offline
    Jacob D Dixon
    wrote on last edited by
    #1

    Hey there! Been a while… took a little break from bugging you all with questions ;-). Anyways I was working on a server/client project so I could just become familiar with socket programming before I took a little "programming" break. Now that I'm going to continue it I had a few questions about trying what I'm attempting to do. What I want is to create a Agent-Based monitoring application. So the idea would be to have the server sitting out on the WAN listening for connections from the agents. The agents will upload data and will perform more actions in the future. So what is the best way to handle multiple connections? The connections could range anywhere from 1 to 750 agents that checkin every 30 seconds. Some products that come in mind is Labtech, Kaseya, and Zenith. I was using async sockets and see tons of people out there just creating new threads on a new connection, but surely this will kill the server when you get many connections. Should I be using a thread pool (haven't dove into how to do this yet), creating new threads, async sockets, or what? Thanks!

    S D B R 4 Replies Last reply
    0
    • J Jacob D Dixon

      Hey there! Been a while… took a little break from bugging you all with questions ;-). Anyways I was working on a server/client project so I could just become familiar with socket programming before I took a little "programming" break. Now that I'm going to continue it I had a few questions about trying what I'm attempting to do. What I want is to create a Agent-Based monitoring application. So the idea would be to have the server sitting out on the WAN listening for connections from the agents. The agents will upload data and will perform more actions in the future. So what is the best way to handle multiple connections? The connections could range anywhere from 1 to 750 agents that checkin every 30 seconds. Some products that come in mind is Labtech, Kaseya, and Zenith. I was using async sockets and see tons of people out there just creating new threads on a new connection, but surely this will kill the server when you get many connections. Should I be using a thread pool (haven't dove into how to do this yet), creating new threads, async sockets, or what? Thanks!

      S Offline
      S Offline
      SungBae Han
      wrote on last edited by
      #2

      maybe... best way use thread pool, and each socket response object use async call back... or anybody suggest more better solution. sorry..

      1 Reply Last reply
      0
      • J Jacob D Dixon

        Hey there! Been a while… took a little break from bugging you all with questions ;-). Anyways I was working on a server/client project so I could just become familiar with socket programming before I took a little "programming" break. Now that I'm going to continue it I had a few questions about trying what I'm attempting to do. What I want is to create a Agent-Based monitoring application. So the idea would be to have the server sitting out on the WAN listening for connections from the agents. The agents will upload data and will perform more actions in the future. So what is the best way to handle multiple connections? The connections could range anywhere from 1 to 750 agents that checkin every 30 seconds. Some products that come in mind is Labtech, Kaseya, and Zenith. I was using async sockets and see tons of people out there just creating new threads on a new connection, but surely this will kill the server when you get many connections. Should I be using a thread pool (haven't dove into how to do this yet), creating new threads, async sockets, or what? Thanks!

        D Offline
        D Offline
        David1987
        wrote on last edited by
        #3

        There is also Socket.Select[^]

        J 1 Reply Last reply
        0
        • D David1987

          There is also Socket.Select[^]

          J Offline
          J Offline
          Jacob D Dixon
          wrote on last edited by
          #4

          Interesting.. never seen that used.. I will have to check more into that.

          1 Reply Last reply
          0
          • J Jacob D Dixon

            Hey there! Been a while… took a little break from bugging you all with questions ;-). Anyways I was working on a server/client project so I could just become familiar with socket programming before I took a little "programming" break. Now that I'm going to continue it I had a few questions about trying what I'm attempting to do. What I want is to create a Agent-Based monitoring application. So the idea would be to have the server sitting out on the WAN listening for connections from the agents. The agents will upload data and will perform more actions in the future. So what is the best way to handle multiple connections? The connections could range anywhere from 1 to 750 agents that checkin every 30 seconds. Some products that come in mind is Labtech, Kaseya, and Zenith. I was using async sockets and see tons of people out there just creating new threads on a new connection, but surely this will kill the server when you get many connections. Should I be using a thread pool (haven't dove into how to do this yet), creating new threads, async sockets, or what? Thanks!

            B Offline
            B Offline
            BobJanova
            wrote on last edited by
            #5

            For a checkin every 30 seconds you might want to consider UDP or reconnecting each time. The recommended way to do TCP is using the asynchronous methods; as you correctly guess creating lots of threads can cause problems. A lot of people (including myself!) start out that way because it's easy, it's how you did it in Java and the documentation for the asynchronous sockets is not that great. What's likely to be the biggest problem in this design is that you will be using up to 750 sockets. That will be a bigger hit than the use of .Net objects with such a low load. A quick search turned up this excellent article on high performance use of the asynchronous socket methods.

            J 1 Reply Last reply
            0
            • J Jacob D Dixon

              Hey there! Been a while… took a little break from bugging you all with questions ;-). Anyways I was working on a server/client project so I could just become familiar with socket programming before I took a little "programming" break. Now that I'm going to continue it I had a few questions about trying what I'm attempting to do. What I want is to create a Agent-Based monitoring application. So the idea would be to have the server sitting out on the WAN listening for connections from the agents. The agents will upload data and will perform more actions in the future. So what is the best way to handle multiple connections? The connections could range anywhere from 1 to 750 agents that checkin every 30 seconds. Some products that come in mind is Labtech, Kaseya, and Zenith. I was using async sockets and see tons of people out there just creating new threads on a new connection, but surely this will kill the server when you get many connections. Should I be using a thread pool (haven't dove into how to do this yet), creating new threads, async sockets, or what? Thanks!

              R Offline
              R Offline
              Rob Philpott
              wrote on last edited by
              #6

              Only one comment - if you've got 750 clients, make sure they connect, do whatever they have to do and disconnect immediately afterwards (or force disconnect them). Holding lots of idle sockets open will kill scalability. This is the approach webservers use. And for lots of short lived connections, the threadpool is definitely your friend. When you accept a socket through a TcpListener or similar pass the socket to a method and throw it on the threadpool.

              Regards, Rob Philpott.

              J 1 Reply Last reply
              0
              • B BobJanova

                For a checkin every 30 seconds you might want to consider UDP or reconnecting each time. The recommended way to do TCP is using the asynchronous methods; as you correctly guess creating lots of threads can cause problems. A lot of people (including myself!) start out that way because it's easy, it's how you did it in Java and the documentation for the asynchronous sockets is not that great. What's likely to be the biggest problem in this design is that you will be using up to 750 sockets. That will be a bigger hit than the use of .Net objects with such a low load. A quick search turned up this excellent article on high performance use of the asynchronous socket methods.

                J Offline
                J Offline
                Jacob D Dixon
                wrote on last edited by
                #7

                I haven't read that link you put up yet but I kind of skimmed through it. It appears that it is using libraries newer than .NET 2.0. I should of mentioned that I wanted to stick with nothing above .NET 2.0. Now for stuff like Labtech I really think they are using a web service (which I do not want to use). I can't really use UDP because the agent has to be able to retrieve data back from that server when it checks in. This is because the server will not really have access to any agent directly since they are on different networks. So the agent has to be the one to start the connection and accept data back.

                B 1 Reply Last reply
                0
                • R Rob Philpott

                  Only one comment - if you've got 750 clients, make sure they connect, do whatever they have to do and disconnect immediately afterwards (or force disconnect them). Holding lots of idle sockets open will kill scalability. This is the approach webservers use. And for lots of short lived connections, the threadpool is definitely your friend. When you accept a socket through a TcpListener or similar pass the socket to a method and throw it on the threadpool.

                  Regards, Rob Philpott.

                  J Offline
                  J Offline
                  Jacob D Dixon
                  wrote on last edited by
                  #8

                  So only handle so many connections at one time… but do not reject any? It almost sounds like if I don't get the calculation right I could end up in a loop (meaning some agent actions not being performed in the correct amount of time before it tries to checkin again)

                  1 Reply Last reply
                  0
                  • J Jacob D Dixon

                    I haven't read that link you put up yet but I kind of skimmed through it. It appears that it is using libraries newer than .NET 2.0. I should of mentioned that I wanted to stick with nothing above .NET 2.0. Now for stuff like Labtech I really think they are using a web service (which I do not want to use). I can't really use UDP because the agent has to be able to retrieve data back from that server when it checks in. This is because the server will not really have access to any agent directly since they are on different networks. So the agent has to be the one to start the connection and accept data back.

                    B Offline
                    B Offline
                    BobJanova
                    wrote on last edited by
                    #9

                    I believe that NAT forwarding automatically makes 'return packet' UDP datagrams work as you'd expect, so as long as the agent started the UDP 'connection' it should be ok. I am not an expert on UDP though. Asynchronous sockets are in .Net 2.0.

                    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