We have a sensor on our local network that is sending a data telegram using UDP Broadcast. How do we use Winsock to capture these messages.

The Port number that the data is being sent on is 42567.

I tried the following code

WinSockControl.Protocol = sckUDPProtocol
WinSockControl.RemotePort = 42567
WinSockControl.Bind

When stepping through this code in the IDE it accepts all these commands however it ver triggers the WinSockControl.DataArrival.

Can anyone tell me what I am doing wrong. I assumed that as the data is being broadcast around my subnet all I need to do is listen.

Thank You

sorry the above should have said it never triggers the WinSockControl.DataArrival

Please show is all the code where you ask the sock to listen for data and where you catch the arrival of said data.

For the test application on the form load I run the following code.

WinSockControl.Protocol = sckUDPProtocol
WinSockControl.RemotePort = 42567
WinSockControl.Bind

I then use the following routine to handle the incoming message. This routine never triggers.

Private Sub WinSockControl_DataArrival(ByVal bytesTotal As Long)
  Dim DataMessage As String
  WinSockControl.GetData DataMessage
End Sub

What am I doing wrong ?

Thanks for your help

JK

The problem seems to be with your server side of the app where the data gets send. If the event does not trigger on the arrival side, it means that it is not receiving anything at all, staying in a static status. What code do you have on the serverside?

We are using a commercial test application to send the message. Using CommView to monitor Port activity we can see the UDP message appearing on Port 42567 and showing the data telegram we expect. But the VB6 application doesn't seem to read it.

Mmmm. gonna have to scratch some head here. Haven't used winsock for ages. I'll search and see what I can get from my old apps or online.

Based on the documentation (Using the Winsock Control) I'd say that you are not performing the Bind properly. You need to specify the local port.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.