Skip to content

Port occupied

George George

Asked May 18, 2008, 9:00 PM EDT2 answers
Share
LinkedInX

Hello everyone,


How to check whether a port on the local machine is occupied by another thread/process? (only whether or not occupied is ok, no need to know which party occupied the port.)

Any samples or APIs to use?


thanks in advance,
George

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    try { Socket.Bind(EndPoint); } catch (Exception error) { }

    try to bind the socket to a local end point and if it throws exception the port is used, don`t worry about opening the socket, bind does not listen yet, you have to call other functions for that ;)
    0
  • 0

    Thanks,

     

    Question answered. :-)

     

    regards,

    George

    0