Hello,
VS 2008 SP1
I have been testing with that code.
However, I find that sometime it works and sometimes it doesn't. Very strange. I am wondering if there is a better way to do this.
I have checked this with netstat -aon (cmd). So I can check to see if the port is open.
I am not sure if it depends on the application using the port or not.
Any suggestions,
Thanks,
VS 2008 SP1
I have been testing with that code.
However, I find that sometime it works and sometimes it doesn't. Very strange. I am wondering if there is a better way to do this.
I have checked this with netstat -aon (cmd). So I can check to see if the port is open.
I am not sure if it depends on the application using the port or not.
Any suggestions,
Thanks,
Code:
private bool IsPortAvailable()
{
System.Net.Sockets.Socket sock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);
bool available = false;
sock.Connect(VaxSIPUserAgentOCX.GetMyIP(), 5060);
if (sock.Connected)
{
//Port is available
available = true;
}
else
{
//Port is blocked
available = false;
}
return available;
}