C# 试图关闭活动TCP连接,但出现错误
我有一个使用ASP.NETC#、javascript和jQuery的web应用程序 我正在尝试关闭页面卸载事件中的某些活动TCP连接 这是我的密码-C# 试图关闭活动TCP连接,但出现错误,c#,asp.net,sockets,tcp,error-handling,C#,Asp.net,Sockets,Tcp,Error Handling,我有一个使用ASP.NETC#、javascript和jQuery的web应用程序 我正在尝试关闭页面卸载事件中的某些活动TCP连接 这是我的密码- IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] connections = properties.GetActiveTcpConnections(); IPAddress ipAddress
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
IPAddress ipAddress = Dns.Resolve(camIP).AddressList[0];
IPEndPoint remEndPoint = new IPEndPoint(ipAddress, 80);
foreach (TcpConnectionInformation c in connections)
{
if (c.RemoteEndPoint.ToString() == remEndPoint.ToString())
{
Socket mySocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
try
{
mySocket.Bind(c.LocalEndPoint);
mySocket.Shutdown(SocketShutdown.Both);
}
catch (Exception ex)
{
}
finally
{
mySocket.Close();
}
}
}
但是,当我尝试绑定时,会出现以下错误-“试图以其访问权限所禁止的方式访问套接字”
TCP连接是通过设置img控件的src创建的-
CameraIframe.Src = @"http://" + CameraHiddenFieldUsername.Value + ":" +
CameraHiddenFieldPassword.Value + "@" + camIP + @"/axis-cgi/mjpg/video.cgi?fps=" +
CameraHiddenFieldfps.Value + "&compression=" + CameraHiddenFieldcompression.Value +
"&resolution=320x240&text=0&date=0&clock=0&eek=" + DateTime.Now.ToBinary();
我是套接字编程新手,因此非常感谢您的帮助。套接字很可能由某个进程持有。使用netstat-o查找哪一个。关闭或“删除”时这不是问题。绑定时出现问题。请相应地修改标题。您正在尝试绑定已绑定的套接字,或者尝试将其绑定到小于1024的本地端口 你所做的一切都没有意义。如果它们是你自己的连接,就关闭它们。 您不需要为此创建新的套接字
当您创建一个新的套接字时,您不需要绑定它,除非您要使用它进行侦听,并且在没有连接它或随后关闭它的情况下关闭它也没有意义。没有办法强制关闭套接字吗?套接字具有PID,并且状态已建立。如何关闭它们?