C# – System.Net.Sockets.SocketException

csocketexception

Encoding en = Encoding.GetEncoding("iso-8859-1"); // default encoding
IPHostEntry IPhst = Dns.GetHostEntry(_Host);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
s.Connect(endPt);

Here am getting the error like:

System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 202.88.253.162:25
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)"

How i can solve this?

Best Answer

The is no server listening at specified ip/port that you are trying to connect to.

Possible causes for the error:

  1. You are using the wrong IP address
  2. You are using the wrong port

Update

Didn't see that you are trying to connect to a SMTP server. Many ISP:s block port 25 for all ip addresses except their own SMTP servers. It's to reduce SPAM emails. So that could be the cause too.

Related Topic