First of all visit
CurrPorts: Monitoring TCP/IP network connections on Windows
and download programm CurrPorts. It seems that C # cannot solve the problem of closing the port. We will use the utility:
private void ClearConnection()
{
string programma = Directory.GetCurrentDirectory() + "\\cports.exe";
string programmParam = "/close * * ";
IPGlobalProperties IPGproperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] connections = IPGproperties.GetActiveTcpConnections();
foreach (TcpConnectionInformation tcp in connections)
{
if (IP_Address.Equals(tcp.RemoteEndPoint.ToString()))
{
string[] parameters = tcp.RemoteEndPoint.ToString().Split(':');
programmParam = "/close * * " + parameters[0] + " " + parameters[1];
Process.Start(programma, programmParam);
}
}
}
Attention! This code must be run on behalf of the Administrator so that there are rights to delete the connection.