I notice that to make the initial TCp Socket connection, it is taking about 4.5 sec.
Socket tcpSocket = new Socket(ipAddress,tcpPort); where ipAddress is a string "xxx.xxx.xxx.xxx" and tcpPort is an int.
Is this about expected time for a TCP Socket connection? or is there something I am missing and could be faster?
Joined: Jan 29, 2003
I'd say you're at the mercy of the network and the partner system. There's not much you can do to improve on those. 4.5 seconds seems like a long time, though, considering your browser connects to remote web sites dozens of times per page sometimes to get all the graphics and CSS files and such and still shows pages faster than that. [ November 28, 2006: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jul 11, 2001
Originally posted by Stan James: I'd say you're at the mercy of the network and the partner system. There's not much you can do to improve on those. 4.5 seconds seems like a long time, though, considering your browser connects to remote web sites dozens of times per page sometimes to get all the graphics and CSS files and such and still shows pages faster than that.
Unless the browser uses "keep-alive" for the connection, which it probably does.
Moving to our Internet Protocols forum...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jan 29, 2003
How would I code a keep alive myself?
Joined: Mar 22, 2005
But that's something the HTTP protocol (version 1.1) adds, not something that works for all TCP/IP connections (although the principle may be applicable, e.g. when using database connection pools). [ November 29, 2006: Message edited by: Ulf Dittmer ]
Ah, HERE is some help from Sun. This is pretty cool:
When the application finishes reading the response body or when the application calls close() on the InputStream returned by URLConnection.getInputStream(), the JDK's HTTP protocol handler will try to clean up the connection and if successful, put the connection into a connection cache for reuse by future HTTP requests.
Guess we get that for free. What a deal.
Now that I think about it, I have a program that downloads a set of files from a server. I can see the first one take a couple seconds to connect but the others have virtually no delay between files.