Hi, Jim.
I can connect to any SMTP server in less than half a second (230
milliseconds on average, 15 milliseconds minimum) with a TcpClient. This
depends on the proximity of the server to your computer and how much stress
the server is under. Below you will find the code and sample output.
I noticed that if you use a hostname instead of it's IP address, it takes a
little longer. This is because you need to resolve the name first (via a DNS
query). Maybe this is what makes your TcpClient implementation take longer
than your COM object implementation.
To answer your question: No, TcpClient should not take 5 seconds to connect.
Hope that helps,
-JG
/////////////////////
/// SmtpConnect.cs //
/////////////////////
using System;
using System.IO;
using System.Net.Sockets;
namespace Cryptomaniac {
public class Crytographer {
static void Main(string[] args) {
DateTime beforeConnect, afterConnect;
TcpClient tc = new TcpClient();
beforeConnect = DateTime.Now;
tc.Connect(args[0], 25);
afterConnect = DateTime.Now;
TimeSpan connectTimeSpan = afterConnect.Subtract(beforeConnect);
Console.WriteLine("Connect time: {0} milliseconds.",
connectTimeSpan.Milliseconds);
NetworkStream ns = tc.GetStream();
StreamReader sr = new StreamReader(ns);
StreamWriter sw = new StreamWriter(ns);
Console.WriteLine("SMTP server greeting: {0}", sr.ReadLine());
sw.WriteLine("quit");
ns.Close();
}
}
}
==================================
=== I ran the program 4 times, ===
=== here are the results: ===
C:\projects\SmtpConnect\bin\Release>SmtpConnect 127.0.0.1
Connect time: 15 milliseconds.
SMTP server greeting: 220 x-force Microsoft ESMTP MAIL Service, Version:
6.0.260 0.1106 ready at Sun, 26 Oct 2003 22:03:59 -0600
C:\projects\SmtpConnect\bin\Release>SmtpConnect mail.atrevido.net
Connect time: 156 milliseconds.
SMTP server greeting: 220 Atrevido SMTP
C:\projects\SmtpConnect\bin\Release>SmtpConnect 65.54.254.151
Connect time: 437 milliseconds.
SMTP server greeting: 220 mc4-f31.hotmail.com Microsoft ESMTP MAIL Service,
Version: 5.0.2195.5600 ready at Sun, 26 Oct 2003 19:58:56 -0800
C:\projects\Cryptomaniac\bin\Release>Cryptomaniac.exe 165.212.8.32
Connect time: 343 milliseconds.
SMTP server greeting: 220 cmsmail09.cms.usa.net ESMTP USA.NET-SMTA
vC8.MAIN.3.08F; Mon, 27 Oct 2003 03:56:58 GMT