我正在创建一个打开侦听TCP / IP端口的服务(使用称为DNP的协议)。
要调试程序,我一直在Program.cs文件中使用这段代码:
static void Main()
{
#if(!DEBUG)
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new ServerDNP()
};
ServiceBase.Run(ServicesToRun);
#else
ServerDNP ServerDNPProcess = new ServerDNP();
ServerDNPProcess.MainProcess();
#endif
}
我的OnStart看起来像这样:
protected override void OnStart(string[] args)
{
this.workerThread = new Thread(new ThreadStart(this.MainProcess));
this.keepRunning = true;
this.workerThread.Start();
}
在实际过程中,我将大量信息输出到日志文件中,以及是否将其作为DEBUG运行或者将该输出释放到该文件中看起来是一样的。
当我以DEBUG运行时,TCP / IP端口打开没问题,我可以从远程机器与它通信。但是,当我将其作为服务运行时,我不断在远程计算机上获得“套接字上没有活动”错误。
为了让它打开TCP / IP端口,我需要为服务做些什么特别的事情吗?我一直在寻找和玩耍一段时间,无法想出任何东西。
答案 0 :(得分:1)
我只是个白痴。
我没有意识到我需要为该过程打开防火墙,而不仅仅是在我将其作为应用程序运行时。