|
-
June 20th, 2002, 02:48 PM
#1
Slow Stream Socket Connection
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?
-
June 21st, 2002, 08:51 AM
#2
Re: Slow Stream Socket Connection
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?
Jared
-
June 21st, 2002, 12:50 PM
#3
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.
-
June 21st, 2002, 12:53 PM
#4
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...
-
June 21st, 2002, 01:29 PM
#5
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
Jared
-
June 21st, 2002, 01:34 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|