Bite my bytes

What I learn by day I blog at night - A blog from Microsoft Consultant working from Ljubljana, Slovenia

  Home :: Contact :: Syndication  
  999 Posts :: 7691 Comments :: 235 Trackbacks

Search

Most popular posts
in last 180 days

Categories

My Projects

Archives

Stuff


Copyright © by David Vidmar
 
Contact me!
 
LinkedIn Profile
 
 
 

A user asked me about GetCanon 1.6 connecting to server in comments in the post about latest GetCanon prerelease. I gave him the quick answer but few hours later I had a feeling something is not right. I took a closer look and I found out that something rather strange is going on.

If you run TCPView and check out the network connections you can see that GetCanon is listed with a connection to mail.teambreskva.com on port 80 (http). First, the address is quite strange. It is the mail server address but the connection is made on port 80 which is obiously not a mail port. And GetCanon does not send emails. The only network connetion that GetCanon makes is at startup when it checks for new version of the program. It does that with super simple web service call to www.vidmar.net. It doesn't send any information and it only recieves the version number, for example "1.6". So what's going on here?

First the address issue. TCPView doesn't know anything about the www.vidmar.net it only sees the IP of the network connection. That IP is the same for many sites on the server, but the reverse lookup can return only one and it returns the URL of mail server.

Second the connection. When connection is made to web service the connection has "keep alive" option turned on. The connection timeout is about 90 seconds. Internally the web request is made using the HttpWebRequest object that uses ServicePoint object to cache the connection and uses it for subsequent request. Mystery solved.

Now to the solution. There is absolutelly nothing I can do about that strange address in TCPView. The GetCanon's homepage IP reverse lookup returns the address and that's it. But the connection can be closed immediately with little coding effort.

Let the code speak for itself. This is the code that has to be added to web service proxy class that Visual Studio creates in reference.cs. Don't forget that the code is generated and will be lost if you regenerate reference.cs. This is excellent example of where the partial class feature from .NET 2.0 will come in handy.

   1:  protected override System.Net.WebRequest GetWebRequest(Uri uri) {
   2:   
   3:      WebRequest request = base.GetWebRequest(uri);
   4:   
   5:      HttpWebRequest httpRequest = request as HttpWebRequest;
   6:      if (httpRequest != null) {
   7:          httpRequest.ServicePoint.MaxIdleTime = 3000;
   8:          ttpRequest.KeepAlive = false;
   9:      }
  10:   
  11:      return request;
  12:   
  13:  }

Thanks to CypherBit, GetCanon will behave like better netizen.

PS: The GetCanon 1.6 is ready. I just have to find some time to publish it.

Posted on Sunday, October 23, 2005 10:43 PM | Filed under: Developement |

Feedback

# re: Connection left open after the web service request 10/25/2005 8:58 PM CypherBit
Great!

I noticed it calling somewhere but didn't bother much with it, apart from blocking it with my firewall. I wouldn't have even posted if it wasn't very persistant.

# re: Connection left open after the web service request 10/25/2005 10:35 PM David
Thanks for noticing. I learned something new!

Comments have been closed on this topic.