Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I am baffled in my attempt to create a Windows service (VB.NET) that can listen to a multicast stream. I have created the service, and have also created a console app with the identical Sub. The console works; but the service gets to the Receive method and never moves past it, but has not stopped. (I've put Console.WriteLines before and after to verify that it's waiting at the Receive.)

I know Windows Services don't allow (or discourage, at least) interacting with the desktop. Is there something about a Windows Service that prevents one from listening to a multicast broadcast?

The service is running under a Domain Admin account, as is the console version.
The service is being installed through a setup project in Visual Studio (2008).
There is a constant flow of data -- in the neighborhood of 50-100 records per second.

Here is my Sub -- again, works as a console app, stalls as a service:
VB
Private Shared Sub BeginListen(ByVal evt As EventLog)
    Dim bteReceiveData() As Byte
    Dim strReceiveData As String

    GroupIP = IPAddress.Parse("230.0.0.0")
    GrpEP = New IPEndPoint(GroupIP, 12345)
    ListenUdp = New UdpClient(12345)
    ListenUdp.JoinMulticastGroup(GroupIP)

    For i As Integer = 1 To 10
        evt.WriteEntry("Inside the Receive loop...initiating Receive...")
        bteReceiveData = ListenUdp.Receive(GrpEP)  '<-- waits here forever
        strReceiveData = Encoding.ASCII.GetString(bteReceiveData, 0, _
                                              bteReceiveData.Length - 1)
    Next
    ListenUdp.Close()
End Sub


I've been scratching/pounding my head on this for the better part of a month and have tried multiple test projects using different techniques. Inevitably, a console or windowsform app works, but the service version doesn't.

Any help will be HUGELY appreciated!
Posted

1 solution

What about firewall ? - If you have Windows Firewall activated. You have to explicitly "Allow" your program/service to receive on UDP port.
 
Share this answer
 
Comments
[no name] 15-Jun-11 16:52pm    
Good thought -- I had not looked at that before, so I just checked it. However, IGMP is in fact enabled/allowed on the firewall. And even so, if the firewall was blocking it, one would expect it to fail for both the service and the console app. Thanks for the thought -- do you have any others?
Kim Togo 16-Jun-11 2:42am    
Try to explicitly "Add program..." in the basic Windows Firewall settings and not only IGMP and UDP port. But allow the your program. Like
http://imgur.com/vnup3.png
TRK3 15-Jun-11 17:50pm    
Only problem I've ever run into with a service is the firewall. I don't know why a service would be treated different than a console program by the firewall but I've seen strange things with firewalls. Try turning the firewall off, just to be sure.
[no name] 16-Jun-11 17:03pm    
Thank you Kim -- it did indeed turn out to be the firewall. I worked through adding the program to the firewall list, and eventually got it to work. Your suggestion was what got me there -- Thanks!
Kim Togo 16-Jun-11 17:08pm    
Great and you are welcome :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900