【发布时间】:2013-12-14 13:42:21
【问题描述】:
我创建了一个小型 Windows 服务,我需要从我自己的 localhost 系统进行连接,但在运行应用程序时出现错误......
No connection could be made because the target machine actively refused it 127.0.0.1:8082
虽然它在实时 ip 和端口号中完美运行,但我需要在 localhost 上对其进行测试,因为我每次都无法访问实时运行的 ip..
这是我的代码...
byte[] data = new byte[1024];
string input, stringData;
String ip = "127.0.0.1";
Int32 port = 8082;
string path = "D:\\";
if (File.Exists("ipsettings.txt"))
{
File.Delete("ipsettings.txt");
}
IPAddress ipad = IPAddress.Parse(ip);
IPEndPoint ipend = new IPEndPoint(ipad, port);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
sock.Connect(ipend);
}
catch (Exception ex)
{
throw ex;
}
此时我遇到了错误..
try
{
sock.Connect(ipend);
}
catch (Exception ex)
{
throw ex;
}
请帮我解决问题.. 提前谢谢..
【问题讨论】:
-
询问服务器有什么问题?
-
@MartinJames 先生,这是本地主机,我的应用程序类型是在调试模式下运行的 Windows 服务
-
“主动拒绝”听起来像是防火墙问题。
-
@Floris 先生如何纠正它
-
查看您在机器上使用的防火墙软件/实用程序。从互联网上拔下,然后关闭所有保护。看看问题是否消失。如果是,请添加规则以允许此连接。如需更多帮助,请添加您在问题中找到的内容的详细信息。记得在重新连接到互联网之前重新打开防火墙!!!
标签: c# sockets localhost tcplistener