[Mono-list] HttpWebRequest differently compared to HttpWebRequest on .Net.

marten.ekblad at relevo.se marten.ekblad at relevo.se
Fri Mar 9 09:37:57 UTC 2012

I have created a client app that communicates with a web service that uses
the Comet way of sending events to a client. To do that I start a
“long-living” HttpWebRequest to the server. The server communicates back to
the client by sending chunked content (Transfer-Encoding: chunked).
Individual events are then transferred in chunks. The problem for me here is
that Mono seems to wait for the connection to terminate or the timeout to
happen before sending the chunks back to the consumer of HttpWebRequest.
This is not the case in .Net. In .Net each chunk is reported back
individually when they arrive. 
This is the pseudo code I’m using:
1.	HttpWebRequest req = WebRequest.Create( URL…);
2.	req.BeginGetRequestStream(…);
3.	stream = eventContext.WebRequest.EndGetRequestStream(…);
4.	StreamWriter writer = new StreamWriter(stream);
5.	writer.Write(data);
6.	writer.Close();
7.	eventContext.RequestStream.Close();
8.	eventContext.WebRequest.BeginGetResponse(…);
9.	HttpWebResponse resp = (HttpWebResponse)
10.	responseStream = resp.GetResponseStream();
11.	responseStream.BeginRead(eventContext.Buffer, 0, 20000, new
AsyncCallback(DataReceived), eventContext);
12.	In DataReceived I do responseStream.EndRead(asynchronousResult);
13.	After that I arm the read again with responseStream.BeginRead(…);

In .Net DataReceived is called on each packet. In Mono it’s called after 30
seconds (probably the timeout).

Is this the intended behavior with HttpWebRequest and chunked content? Is
there another recommended way of dealing Comet style web services? 

View this message in context: http://mono.1490590.n4.nabble.com/HttpWebRequest-differently-compared-to-HttpWebRequest-on-Net-tp4458958p4458958.html
Sent from the Mono - General mailing list archive at Nabble.com.

More information about the Mono-list mailing list