TCPListener works in Win app but not in service app

G

Guest

(Note: the TCP Client is on another machine, and attempts communication every
minute.)

Both apps use the same assembly
The service app starts thusly, creating the tcp object and starting the
timer in the OnStart event. The timer calls OpenServer (one time):

Public Class TCPService
Private tcp As SimpleTCP
Private Timer1 As Timer

Protected Overrides Sub OnStart(ByVal args() As String)
tcp = New SimpleTCP
Timer1 = New Timer(50)
AddHandler Timer1.Elapsed, New
System.Timers.ElapsedEventHandler(AddressOf Timer1_Tick)
Timer1.Start()
End Sub

Protected Overrides Sub OnStop()
Timer1.Enabled = False
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs)
Timer1.Enabled = False
tcp.OpenServer(Nothing)
End Sub
End Class

The win app is the same, really just a tester for the logic in the service,
except it creates the tcp object in form load and calls OpenServer in a
button click.


In the OpenServer method:

Server = New TcpListener(cfg.Port)
....
Try
Server.Start()
metrics.Log(LogNameServer, SourceNameServer, "Server.Start")
Running = True
While Running
If Server.Pending Then
metrics.Log(LogNameServer, SourceNameServer,
"Server.Pending")
Dim TalkThread As Thread = New Thread(TalkDelagate)
TalkThread.Start()
End If

If Not (Respond Is Nothing) Then
Respond.Invoke()
End If
End While

metrics.Log(LogNameServer, SourceNameServer, "End While")

Catch ex As Exception
Dim S As String = ex.Message
metrics.Log(LogNameServer, SourceNameServer, S)
End Try


I have confirmed that in OpenServer, both apps use the exact same values and
follow the exact same program flow. In the win app, it just plain works. In
the
service app (I do NOT have them running at the same time), Server.Pending is
always false, no matter how much data is waiting to be picked up. Running is
always true.

I considered that maybe I need the new constructor for TCPListener, so I used:
Server = New TcpListener(IPAddress.Any, cfg.Port)
instead, but that made no difference.

Why would the server version simply fail to detect that data is pending?

Thanks,

Jon
 
G

Guest

use a system threading timer and it wil work
Thanks but...
Sorry I didn't show this peice of code:
Imports System.Timers

The timer DOES fire.

The problem is that it DOES get to this code:
If Server.Pending Then

but Server.Pending is always FALSE no matter how much data is pending.

I've traced the code execution very carefully. The timer is not the issue.

Any idea why the listener is not listening right?

Thanks,
Jon
 
M

Michael D. Ober

Make sure your service logs in with an account that has network access. The
default "LocalSystem" account does not have network access.

Mike.
 
G

Guest

Make sure your service logs in with an account that has network access. The
default "LocalSystem" account does not have network access.
Thank you, Mike.

I tried it logging in with my user account, which for sure does have the
network access, the same account by which the win app version worked fine.
The service version does not work even then.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top