I am writing a program. my program receives data from the server via the HTTP protocol. the data will be redirected by the server to my program. I tried using WebRequest but got only one data session. How can I maintain a network connection, constantly receive data from the server, Any help is appreciated.
Below is the SDK document:
With the permission of GUEST or ADMIN, you can get a series of live images (Server load). To get the images, send a request to "/liveimg.cgi?serverpush=1" as shown. 2-1-1.
When the camera receives the above request from the client, it sends a refund, as shown in the figure. 2-2.
Each JPEG data is separated by "-myboundary", and "image / jpeg" is returned as a "Content-Type" header, after "--myboundary". For the Content-Length header, it returns the number of bytes in the -myboundary data (excluding "-myboundary", each header, and \ r \ n as a delimiter). After the header "Content-Length" and "\ r \ n" (delimiter) the actual data will be sent.
This data transfer will continue until the client stops the connection (disconnect) or some network error occurs.
int len; string uri = @ " http://192.168.0.2/liveimg.cgi?serverpush=1 ";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);
req.Credentials = new NetworkCredential("admin", "admin");
req.KeepAlive = true;
string line = "";
HttpWebResponse reply = (HttpWebResponse)req.GetResponse();
Stream stream = reply.GetResponseStream();
System.Diagnostics.Debug.WriteLine(reply.ContentType);
StreamReader reader = new StreamReader(stream);
do
{
line = reader.ReadLine();
System.Diagnostics.Debug.WriteLine(line);
System.Threading.Thread.Sleep(300);
} while (line.Length>0);
bin
source
share