Hi,
I am implementing an application with tcp communication using the class
System.Net.Sockets.TcpClient, but the connection process require 10 seconds
or more, in the code line:
TcpClient tcpClient = new TcpClient(ip, port);
or
tcpClient.Connect();
When I use a TcpPower component, I don't need more than 1 second in the
connection.
Anybody have some idea about the reason for this behavior and how I can
reduce the connection time ?
Thanks a lot for your help.
Steve Lutz - 25 Mar 2005 04:20 GMT
My guess is it is the time for DNS to resolve, since you are using the
constructor:
public TcpClient(
string hostname,
int port
);
if you know the IP address, then use the constructor:
[C#]
public TcpClient(
IPEndPoint localEP
);
The following example demonstrates how to create an instance of the
TcpClient class using a local endpoint.
//Creates a TCPClient using a localend point.
IPAddress ipAddress = ipaddress;
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, port);
try{
TcpClient tcpClientA = new TcpClient(ipLocalEndPoint);
}
catch (Exception e ) {
Console.WriteLine(e.ToString());
}
(Sample is from MSDN)
> Hi,
> I am implementing an application with tcp communication using the class
[quoted text clipped - 11 lines]
>
> Thanks a lot for your help.