0

I have client-server app, which is using WCF port sharing feature for communication between each other. In case, when I installing both parts on the same machine I need to use the same port. The question is, how can I distinguish during installation, is some port is busy or used by another part of my app and can be shared.

Any suggestions? Many thanks.

mxpv
  • 946
  • 2
  • 10
  • 31

2 Answers2

1

To do it in code... look at this question...

In C#, how to check if a TCP port is available?

That should get you there...

Community
  • 1
  • 1
Martin
  • 2,180
  • 4
  • 21
  • 41
  • I need to recognize that port is busy or port is busy and can be shared. – mxpv Jan 13 '12 at 09:39
  • you can't "share" *TCP* ports. only 1 application can listen on a port at a time. therefore if the port is busy (has an active listening connection), then it cannot be used by your application – Martin Jan 13 '12 at 12:54
  • Ah... as far I'm aware, the only way to do this would be to use the name of the listening process (it should be the port sharing service), or just try to connect and catch the exception. I would say that the majority of applications don't use this service though, so you're targetting mainly obscure apps, or possibly your own. – Martin Jan 13 '12 at 21:02
0

You can use telnet to check if a port is busy.

For windows Go to startpanel and type cmd then type

C:>telnet localhost 52753

or any other portnumber then 52753. If you have a web server running, you will go on to a blank screen if using port 80 and typing: C:>telnet localhost 80

If a port is not in use then a message will tell you that the connection failed.

Per G
  • 375
  • 1
  • 4
  • 18