简体   繁体   English

System.Net.Sockets.SocketException

[英]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)" System.Net.Sockets.SocketException:连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接的主机未能响应 202.88.253.162:25 在 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.没有服务器在您尝试连接的指定 ip/端口进行侦听。

Possible causes for the error:错误的可能原因:

  1. You are using the wrong IP address您使用了错误的 IP 地址
  2. You are using the wrong port您使用了错误的端口

Update更新

Didn't see that you are trying to connect to a SMTP server.没有看到您正在尝试连接到 SMTP 服务器。 Many ISP:s block port 25 for all ip addresses except their own SMTP servers.许多 ISP:s 阻止所有 ip 地址的端口 25,除了他们自己的 SMTP 服务器。 It's to reduce SPAM emails.这是为了减少垃圾邮件。 So that could be the cause too.所以这也可能是原因。

Try using the IP 127.0.0.1.尝试使用 IP 127.0.0.1。 It might work.它可能会起作用。

I changed port 25 to 587 in my code.我在代码中将端口 25 更改为 587。

SmtpServer.Port = 587;

And it stared working =)它开始工作了=)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 postgres 连接上的 System.Net.Sockets.SocketException - System.Net.Sockets.SocketException on postgres connection System.Net.Sockets.SocketException 灾难 - System.Net.Sockets.SocketException Disaster .NET服务System.Net.Sockets.SocketException:'未知此类主机' - .NET Service System.Net.Sockets.SocketException: 'No such host is known' System.Net.Sockets.SocketException (0x80004005): 没有这样的主机是已知的 - System.Net.Sockets.SocketException (0x80004005): No such host is known 2008R2服务器上的System.Net.Sockets.SocketException - System.Net.Sockets.SocketException on 2008R2 Server EventHub 发送消息,但 Application Insights 上的 System.Net.Sockets.SocketException - EventHub send message, but System.Net.Sockets.SocketException on Application Insights 使用Azure时Visual Studio中的System.Net.Sockets.SocketException - System.Net.Sockets.SocketException in Visual Studio while using Azure System.Net.Sockets.SocketException:'提供了无效的参数' - System.Net.Sockets.SocketException: 'An invalid argument was supplied' System.Net.Sockets.SocketException(0x80004005) - System.Net.Sockets.SocketException (0x80004005) 查找导致异常的确切原因-System.Net.Sockets.SocketException - Finding the exact cause for the exception - System.Net.Sockets.SocketException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM