VB.NET服务中的Tcplistener无法正常工作 [英] Tcplistener in VB.NET service not working

查看:225
本文介绍了VB.NET服务中的Tcplistener无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我必须遗漏一些东西,但已经搜索了几个小时但找不到了!

我有一个工作的VB.net表单应用程序,我是试图转换为服务。我在下面使用了相同的代码。它适用于表单应用程序,但不适用于服务。

Hi,
I must be missing something but have searched for hours and can't find what!
I have a working VB.net forms app which I am trying to convert to a Service. I've used the same code, below, in both. It works in the forms app but not in the service.

.....
            listener = New TcpListener(Net.IPAddress.Any, Port)
            listener.Start()
            listenThread = New Threading.Thread(AddressOf WaitForRequest)
            listenThread.IsBackground = True
            listenThread.Start()
.......

 Private Sub WaitForRequest()
        Try
            Dim recclient As New TcpClient
            While True
                Log("wait")
                recclient = listener.AcceptTcpClient
                Log("receiving")
......



(日志将字符串写入文件,它同时适用于案例)

该服务设置为使用具有网络访问权限的管理员用户帐户。

应用程序正常工作,当收到某些内容时,日志正在接收然后继续;服务永远不会超过wait/ recclient =。

监听器正在监听 - 如果我在服务运行时尝试启动应用程序,我会得到'每个套接字只有一次使用... ..'错误。当我停止服务时,我记录'阻塞操作被调用WSACancelBlockingCall ...'错误。

我想这是显而易见的但是我看不到它!

有人可以帮忙吗?谢谢。



我尝试了什么:



我试过了LocalService,LocalSystem和NetworkService。 NetworkService听起来很有希望,但不会运行。

代码的各种排列但是给出的似乎是最接近的运行 - 它只是不起作用!!

有事件日志中没有任何内容。


(log writes the string to a file, it works in both cases)
The service is set to use an administrator user account which has network access.
The app works and when something is received logs "receiving" then continues; the service never gets past "wait"/ recclient =.
The listener is listening - if I try to start the app when the service is running I get an 'only one usage of each socket.....' error. And when I stop the service I log 'A blocking operation was interrupted by a call to WSACancelBlockingCall...' error.
I guess it's something obvious but I just can't see it!
Can anyone help? Thanks.

What I have tried:

I've tried LocalService, LocalSystem and NetworkService. NetworkService sounded promising but wouldn't run.
Various permutations of code but what's given seems to be the nearest to running - it just doesn't work though!!
There's nothing in the events log.

推荐答案

防火墙问题!我认为它不会阻止本地访问! Windows 10。
Firewall issue! I didn't think it would block local access! Windows 10.


这篇关于VB.NET服务中的Tcplistener无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆