Checking if a UDP port is open
-
Hello, VS2008 SP1
Private Function IsPortAvailable() As Boolean Using sock As New Socket(AddressFamily.InterNetwork, _ SocketType.Dgram, _ ProtocolType.Udp) sock.Connect(VaxSIPUserAgentOCX.GetMyIP(), 5060) Return sock.Connected End Using End Function
Using this code I thought I had this problem solved. However, after testing I have found that the socket always connects. Even if the port is being used by another application. The port I am checking is 5060 UDP. My application when it starts will check if this is available. If another applications is using it. i.e. SJ Phone etc. The application will inform the user. However, the socket always returns true. I have checked this with netstat -aon (cmd) and I can see that the port is being used. I am checking the port on my local computer. So my IP address is 10.10.10.120. Under the netstat I can see this 0.0.0.0:5060. Why all the zeros. Could this be part of the problem Is there another method for checking this? I have looked at udp client, and wondering about winsock. Thanks,