Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Hello

I have a web application written asp.net, c#, javascript and JQuery.

One of the pages has an image control. When the page loads the source attribute is set to an URL of a web cam:

C#
CameraIframe.Attributes["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&v=" + DateTime.Now.ToLongTimeString();


This creates a TCP connection. On the page we have a button "Take Picture". When the user selects this button it does a post back. On the Page_Load the src of the Image is again set to the web camera url, again creating a new TCP Connection. However the old TCP connection is still there. If the user takes a number of pictures, then a number of TCP connections are created.

Is there a way that I can close the TCP connection created by the image control in the Page_Unload event?

I have never dealt with TCP before, so please be gentle!

Thank you.
Posted
Comments
Homero Rivera 14-Feb-14 23:14pm    
I think more of that code would be good to see. That's C# is that right?
TCP is a protocol where both parties need confirmation that all information has been sent so communication closes. The TCP socket should close when all data packets have been sent and client has confirmed reception of all of them. What is the code of the client? Did you program the reception of the image by the client?
Kev45 18-Feb-14 9:03am    
Hello.

There isn't much more code I can give you. Yes, it is C#.

<pre lang="c#">
string camIP = string.Empty;

CameraIframe.Attributes["src"] = string.Empty;

if (!string.IsNullOrEmpty(TerminalLinkedDropDownList.FirstLevelChildCvKey))
{
foreach (var ip in CamIPs.Value.Split('|'))
{
if (ip.Split('-')[0] == TerminalLinkedDropDownList.FirstLevelChildCvKey)
{
camIP = ip.Split('-')[1];
}
}

if (!string.IsNullOrEmpty(camIP))
{
CameraHiddenFieldfps.Value = ConfigurationManager.AppSettings["CameraFps"].ToString();
CameraHiddenFieldcompression.Value = ConfigurationManager.AppSettings["CameraCompression"].ToString();

NameValueCollection myParamsCollection = (NameValueCollection)ConfigurationManager.GetSection("secureAppSettings");
CameraHiddenFieldUsername.Value = myParamsCollection["CameraUsername"];
CameraHiddenFieldPassword.Value = myParamsCollection["CameraPassword"];

CameraIframe.Attributes["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&v=" + DateTime.Now.ToLongTimeString();

}
}
</pre>

I didn't write the original code. The person has left. All I can see is that the code connects the URL to the src attribute of the image control. It is a live web cam feed. So is open all the time.

When the "Take image" button is clicked, it does a page load, and again connects the url to the src attribute of the image control, so that we have the live web cam feed.
Homero Rivera 18-Feb-14 23:13pm    
Sorry pal, beats me. I have no idea what those classes do on every step.
Best,
Kev45 19-Feb-14 4:43am    
Thanks anyway.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900