【发布时间】:2014-02-13 13:18:25
【问题描述】:
我有一个使用 ASP.net c#、javascript 和 jQuery 的 Web 应用程序。
我试图在我的 PAGE_UNLOAD 事件中关闭某些活动的 TCP 连接。
这是我的代码 -
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();
}
}
}
但是,当我尝试绑定时,我收到以下错误 - “尝试以访问权限禁止的方式访问套接字”
通过设置img控件的src创建TCP连接-
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();
我是套接字编程的新手,因此我们将不胜感激。
【问题讨论】:
标签: c# asp.net sockets tcp error-handling