简体   繁体   中英

System.Net.Sockets.SocketException

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?

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.

Try using the IP 127.0.0.1. It might work.

I changed port 25 to 587 in my code.

SmtpServer.Port = 587;

And it stared working =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM