开发者

System.Net.Sockets.SocketException

开发者 https://www.devze.com 2023-03-12 15:03 出处:网络
Encoding en = Encoding.GetEncoding(\"iso-8859-1\"); // default encoding IPHostEntry IPhst = Dns.GetHostEntry开发者_开发问答(_Host);
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 =)

0

精彩评论

暂无评论...
验证码 换一张
取 消