Consider the following scenario, a servlet has been written in Java and once you connect to the servlet, it starts writing to the OutputStream, let’s say 10 million bytes, 1 byte at a time.
You have a client program which reads the servlet’s response stream and reads say 100 bytes and calls close. Now if your client program is in Java, the streams close immediately and the server stops sending the content, but if the client program is in C#, the close call takes a long time to finish because it apparently waits for server to finish writing all the 10 million bytes.
So, I have two questions on this,
- Why does C# behave differently?
- What can I do to ensure the Close call on the C# stream closes the stream immediately and does not allow the server to keep sending the data?
Any pointers will be greatly appreciated 🙂
So, I finally figured this out a couple of weeks back and verified it with Microsoft as well. The difference between C# and Java is the fact that in Java close call closes the request/connection as well, while in C#, it doesn’t happen unless you follow it up with an xxxRequest.Abort() call. Hope this helps someone else as well.