Click to See Complete Forum and Search --> : Slow Stream Socket Connection
stolentomato
June 20th, 2002, 02:48 PM
I'm connecting to a remote server via a stream socket and am experiencing exceptionally slow connection times. For example, using a valid IP address and port number, the following code finishes connecting to the server in 4 to 7 seconds. using System;
using System.Net.Sockets;
*****************************************
namespace TCPClient
{
public class TCPClient
{
public TCPClient()
{
TcpClient client;
client = new TcpClient();
client.Connect("123.123.123.123", 99999);
}
static void Main()
{
new TCPClient();
}
}
}
*****************************************
Corresponding code in Java, or C++ completes in a few milliseconds.
Does anybody have any suggestions as to why this may be occurring?
jparsons
June 21st, 2002, 08:51 AM
Originally posted by stolentomato
I'm connecting to a remote server via a stream socket and am experiencing exceptionally slow connection times. For example, using a valid IP address and port number, the following code finishes connecting to the server in 4 to 7 seconds. using System;
using System.Net.Sockets;
*****************************************
namespace TCPClient
{
public class TCPClient
{
public TCPClient()
{
TcpClient client;
client = new TcpClient();
client.Connect("123.123.123.123", 99999);
}
static void Main()
{
new TCPClient();
}
}
}
*****************************************
Corresponding code in Java, or C++ completes in a few milliseconds.
Does anybody have any suggestions as to why this may be occurring?
Have you tried using a plain Socket and connecting that way?
stolentomato
June 21st, 2002, 12:50 PM
oh, so there's another way to "skin the cat". This is my first wack at an application with C#. I didn't realize there was an alternative. I went back and used the regular socket and saw dramatic improvements in the connection time.
Thanks very much for the tip.
Arild Fines
June 21st, 2002, 12:53 PM
That still doesnt explain it though - TcpClient may have some overhead, but not 4-7 seconds.
99999 is an invalid port number, by the way...
jparsons
June 21st, 2002, 01:29 PM
Originally posted by Arild Fines
That still doesnt explain it though - TcpClient may have some overhead, but not 4-7 seconds.
99999 is an invalid port number, by the way...
His original post said he was doing this with a valid port and IP
stolentomato
June 21st, 2002, 01:34 PM
Yes, "99999" is an invalid port number.
In the original post, the code uses bogus IPAddr, and port values. It's mentioned also that using "valid" IPAddr and port values the example code yields 4 to 7 second connection timings. I couldn't agree more that this is unacceptable in a production application.
However, Jared pointed out that using a "plain" socket may be an avenue of pursuit. As it turned out, the plain socket hooked up to my server as expected; that is, subsecond speeds for the first pass at the connection, and connection speeds that were immeasurable for subsequent connections.
Maybe the reason for a 4 to 7 second connection time hasn't been provided, but the desired result has been achieved.
Thanks again for the help, Jared.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.