473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

TCPListener works in Win app but not in service app

(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
Sep 5 '07 #1
4 3404

use a system threading timer and it wil work
hth

Michel
"Jon Jacobs" <Jo*******@discussions.microsoft.comschreef in bericht
news:4B**********************************@microsof t.com...
(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

Sep 6 '07 #2
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
Sep 6 '07 #3
Make sure your service logs in with an account that has network access. The
default "LocalSystem" account does not have network access.

Mike.

"Jon Jacobs" <Jo*******@discussions.microsoft.comwrote in message
news:BA**********************************@microsof t.com...
>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


Sep 8 '07 #4
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
Sep 10 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Keith Langer | last post by:
I have a TCPListener which needs to listen on my LAN IP as well as the loopback address. In VS.Net 2002 the TCPListener constructor could accept the port as an argument and it automatically bound...
4
by: byron guerrero | last post by:
I need to execute a TcpListener in a windows service. tanks for the help.
1
by: Doug Wyatt | last post by:
So I'll preface this with the fact that I'm a UNIX developer by training and have just recently gotten in to C# development on Windows. I'm basically running in to a problem whereby I suspect...
4
by: Rob White | last post by:
OK, so I have a TcpListener that is waiting for sockets, this piece of code: IPAddress localAddress = Dns.GetHostByName(Dns.GetHostName()).AddressList; IPEndPoint localEP = new...
2
by: Dave Coate | last post by:
Hi, I am working on a client-server app. I can get two applications to talk to each other on the same machine using 127.0.0.1, but as soon as I try it using a computer name or actual IP address...
2
by: Terry Olsen | last post by:
Hoping someone can help me here. I've got this code written, and it works fine for the first connection. But if I connect another client (while the first is still connected), I get connected but...
0
by: bertymaes | last post by:
Hi, I'm using VB in VS2005 on a WXP SP2 machine to build a windows service that listens to a port to accept messages. This solution works fine when a connecting client sends a message, waits for...
3
by: Bjørn Eliasen | last post by:
Hi, I have an application running on all pc's in our company. Basically it is a TCPListener awaiting for sockets to connect and on connection performs the required tasks. The app works fine, but...
2
by: =?Utf-8?B?Sm9uIEphY29icw==?= | last post by:
I use in vb (VS2005) Server = New TcpListener(PortNumber) Which is simple and straightforward. But I get Public Sub New(port As Integer) is obsolete: This method has been deprecated. Please...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.