Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I close a URLConnection?  RSS feed

 
Li Shangqiang
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm developing a Applet, which get data from Server(not servlet). To go through proxy/firewall, i use URLConnection to connect to Server.
But now have a question: should client side or server side close the socket?
First i implement it as closing the socket on server side, but because the TCP TIME-WAIT effect, after a short while there will be many sockets in TIME-WAIT status on server. But i can't find any method of URLConnection that close the connection(socket). Who can help me?
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using URLConnection you don't need to close the connection or close the underlying sockets. At the most you may close the stream derived from the URLConnection.
In the HTTP request-response stateless protocol, the server will automatically close the socket after sending its response, and the client will automatically close its socket after receiving the response. There is nothing more to it I think.
URLConnection is a 'high-level' class relieving you of the burden of dealing with the 'low-level' class like Socket.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!