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. TcpListener : Best approach to check the active connections

TcpListener : Best approach to check the active connections

Scheduled Pinned Locked Moved C#
sysadminquestion
4 Posts 2 Posters 2 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.
  • Z Offline
    Z Offline
    Zishan Haider
    wrote on last edited by
    #1

    hello, I have programed a MultiThreaded TCP server using TcpListener, TcpClient and NetworkStream. What can be the best approach to check the active connections and close the inactive ones? I am looking for some way so that when client closes the connection only then the connection closes, regardless if the comunication has taken place or not for a long time. Is there any way? Zishan

    D 1 Reply Last reply
    0
    • Z Zishan Haider

      hello, I have programed a MultiThreaded TCP server using TcpListener, TcpClient and NetworkStream. What can be the best approach to check the active connections and close the inactive ones? I am looking for some way so that when client closes the connection only then the connection closes, regardless if the comunication has taken place or not for a long time. Is there any way? Zishan

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      Set the SendTimeout and ReceiveTimeout on the classes and the framework will do this for you :) Yes, even I am blogging now!

      Z 1 Reply Last reply
      0
      • D Daniel Turini

        Set the SendTimeout and ReceiveTimeout on the classes and the framework will do this for you :) Yes, even I am blogging now!

        Z Offline
        Z Offline
        Zishan Haider
        wrote on last edited by
        #3

        Actually I have an array of TcpClient and equal number of Threads for each client at the server. I have another thread (connectionDestructorThread) that is checking all these clients. If any client disconnects, this connectionDestructorThread should get the notification and aborts that client's Thread and free up resources. I don't see how SendTimeout and ReceiveTimeout can help in this senario. regards, Zishan

        Z 1 Reply Last reply
        0
        • Z Zishan Haider

          Actually I have an array of TcpClient and equal number of Threads for each client at the server. I have another thread (connectionDestructorThread) that is checking all these clients. If any client disconnects, this connectionDestructorThread should get the notification and aborts that client's Thread and free up resources. I don't see how SendTimeout and ReceiveTimeout can help in this senario. regards, Zishan

          Z Offline
          Z Offline
          Zishan Haider
          wrote on last edited by
          #4

          Yes I did it!!! Thanks for the help. :-) Best Regards, Zishan

          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