How to control TCP/IP connections used with HttpWebRequest ?

J

Jacek

Hi All!

After checking with packet sniffer that for every created HttpWebRequest /
HttpWebResponse followed by Close() call my box creates new TCP/IP
connection I just wonder if there is a way to use single long lasting TCP/IP
connection with a given server for multiple HttpWebRequest / HttpWebResponse
operations.

Any ideas?
 
J

Joerg Jooss

Jacek said:
Hi All!

After checking with packet sniffer that for every created
HttpWebRequest / HttpWebResponse followed by Close() call my box
creates new TCP/IP connection I just wonder if there is a way to use
single long lasting TCP/IP connection with a given server for
multiple HttpWebRequest / HttpWebResponse operations.

Any ideas?

Can you post some code? Reusing a TCP connection is what persistent
connections in HTTP 1.1 (or keep-alive in 1.0) are all about, and these
features are all implemented by HttpWebRequest.

Cheers,
 
F

Feroze [msft]

By default, HttpWebRequest tries to use persistent connections. Now, if the
server is closing the connection after each request, then the client will be
forced to create a new one.

Also, are you tweaking any connection related properties on the webrequest
object, like: KeepAlive, ConnectionGroupName etc? Depending on what you set
there, it might affect connection reuse also

To answer your question, setting request.KeepAlive=true causes connection to
be reused.
--
feroze

-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.

See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top