0

Using Visual Studio 2010 - C#

Our agency has Utility Mobile Vehicle Rockets. These devices are essentially a mobile wifi router that you plug a broadband card into. They also have a built-in GPS module, and one of the features of the device is that it has MultiCast and will send the GPS coordinates (among other information) over the multicast. What I am trying to do is capture the data coming from this device and then do various things with the GPS information.

I've tried to wrap my head around Multicast and have tried numerous different code to try and capture the data. Alas, I have not been able to capture a single piece of information to be able to process. The settings on the Rocket device for Multicast are:

  • MultiCast Address: 224.0.0.1
  • MultiCast Port: 4004
  • MultiCast TTL: 16

Below is the code I have been trying to use, which I got from here in Listing 10.10 (This page was referenced in several other StackOverflow questions...) When I run the console program, it just sits there and no information appears on the screen. I do not get any exception messages from the Try/Catch block. I know that the computer is receiving information from the Rocket because Utility's own "monitoring program" gets updated every few seconds, and WireShark shows that something is happening on that port (although I have no idea how to read it and don't fully understand it...) Is there something I am missing...? Note: I am not using Utility's own monitoring program while I'm running this code...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace MulticastUDPListener
{
    class Program
    {
        private static void StartListener()
        {
            try
            {
                UdpClient sock = new UdpClient(4004);
                Console.WriteLine("Ready to receive…");
                sock.JoinMulticastGroup(IPAddress.Parse("224.0.0.1"), 50);
                IPEndPoint iep = new IPEndPoint(IPAddress.Any, 0);
                byte[] data = sock.Receive(ref iep);
                string stringData = Encoding.ASCII.GetString(data, 0, data.Length);
                Console.WriteLine("received: {0} from: {1}", stringData, iep.ToString());
                sock.Close();
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }

        static void Main(string[] args)
        {
            StartListener();
        }
    }
}
Jason Miller
  • 183
  • 5
  • 10

0 Answers0