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. socket not closing even after the listening app has terminated?!

socket not closing even after the listening app has terminated?!

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 1 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.
  • D Offline
    D Offline
    Druuler
    wrote on last edited by
    #1

    hi! i have a very weird problem: i have an app which listens for connections, and once a client connects it starts anothter app, now if the main listening app terminates but app2 is still running then the port isnt released and when the main app starts up again and try to bind to the port it fails (port already in use). the port is first released when app2 or all of its child processes has terminated, but these processes has nothing to with the main app, so why isnt port released after the main app has been terminated?

    D 1 Reply Last reply
    0
    • D Druuler

      hi! i have a very weird problem: i have an app which listens for connections, and once a client connects it starts anothter app, now if the main listening app terminates but app2 is still running then the port isnt released and when the main app starts up again and try to bind to the port it fails (port already in use). the port is first released when app2 or all of its child processes has terminated, but these processes has nothing to with the main app, so why isnt port released after the main app has been terminated?

      D Offline
      D Offline
      Druuler
      wrote on last edited by
      #2

      After little more investigation with process hacker (Process Hacker/[^]) i see that the apps started from the main listening app and there child process gets the handle to the named pipes and somthing called \device\afd that main app has created, if i close those handles then the port is released, if i dont then the main app actuallty keeps running and listening on that port according to process hacker but doenst respond to incoming connections. :wtf: so the main app, after its terminated doenst show upp in process list/taskmanager or netstat tool but shows up as UnknownpProcess in process hackers "network connections" listening on the port??:confused: How can i fix this? This is how the app currently works... My App --> starts app2 and creates pipes. Now if my app gets terminated then app 2 is also terminated, but i have no control of which apps app2 might start and they are not terminated once app2 gets terminated so they keeps the handle to named pipes and (mainly)device\afd and keeps the port busy?

      D 1 Reply Last reply
      0
      • D Druuler

        After little more investigation with process hacker (Process Hacker/[^]) i see that the apps started from the main listening app and there child process gets the handle to the named pipes and somthing called \device\afd that main app has created, if i close those handles then the port is released, if i dont then the main app actuallty keeps running and listening on that port according to process hacker but doenst respond to incoming connections. :wtf: so the main app, after its terminated doenst show upp in process list/taskmanager or netstat tool but shows up as UnknownpProcess in process hackers "network connections" listening on the port??:confused: How can i fix this? This is how the app currently works... My App --> starts app2 and creates pipes. Now if my app gets terminated then app 2 is also terminated, but i have no control of which apps app2 might start and they are not terminated once app2 gets terminated so they keeps the handle to named pipes and (mainly)device\afd and keeps the port busy?

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

        the problem was that all processes was inherting sockets handle :sigh: Anyhow i thought i might post the solution if any1 else have same problem, simply use SetHandleInformation [^]thru pinvoke!

        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