Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 501803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:13:38+00:00 2026-05-13T06:13:38+00:00

I have the following UDP broadcast listener running as a static component in a

  • 0

I have the following UDP broadcast listener running as a static component in a seperate thread on an ASP.NET web application. Why I would do this is really, unimportant, but the reason why this wont work when deployed baffles me. I do have several console applications sending UDP broadcasts, and I’ve coded tested and confirmed this thread and its code working when running under Visual Studio on the VS2005 development web server, but the moment that I compile the code and deploy it to another machine and run it under IIS – it stops working. Furthermore, it doesnt ERROR, it just doesn’t work.

The log4net logging also seems to only work in the Init() method, but not the thread (which is weird). But I have added some File.AppendAllText‘s to the thread and it DOES seem to be executing, but as far as I can tell, it stops on the line byte[] received = mUdpClient.Receive(ref mGroupEP);

I’ve made sure the port is open and tested in a console app (which works), I’ve checked permissions, even made the default identity use the Local System user account, but still nothing. I’ve checked the firewall, checked the event log – nothing. No errors, just not working.

I wondered if it might be somehting to do with IIS shutting down System.Net requests as a security meassure, but I can’t find anything that might support that hypothesis.

  public class UDPBroadcastListener {

    #region Members

    private ILogger mLogger = NullLogger.Instance;

    private readonly int mPort;
    private UdpClient mUdpClient;
    private IPEndPoint mGroupEP;

    public event EventHandler<GenericEventArgs<byte[]>> Received;

    private Thread mThread;

    #endregion

    public UDPBroadcastListener(int port) {
      mPort = port;
    }

    public void Init() {
      try {
        Logger.WarnFormat("Setting up the UDP packet listener on port {0}", mPort);
        mGroupEP = new IPEndPoint(IPAddress.Any, mPort);
        mUdpClient = new UdpClient();
        mUdpClient.EnableBroadcast = true;
        mUdpClient.Client.SetSocketOption(SocketOptionLevel.Socket,
                                          SocketOptionName.ReuseAddress,
                                          true);
        mUdpClient.Client.Bind(mGroupEP);
        Logger.InfoFormat("Successfully bound the UDP packet listener to the the port.");

        mThread = new Thread(UpdateThread);
        mThread.IsBackground = true;
        Logger.Info("Starting the background listener thread.");
        mThread.Start();
        Logger.InfoFormat("Background listener thread started ok.");
      } catch (Exception e) {
        Logger.Error(e.Message, e);
      }
    }

    public void Close() {
      if (mThread != null) {
        mThread.Abort();
      }

      if (mUdpClient != null) {
        mUdpClient.Close();
        mUdpClient = null;
      }
    }

    public Thread Thread {
      get { return mThread; }
    }

    private void UpdateThread() {
      Logger.Info("Listener thread started.");
      while (true) {
        try {
          Logger.Info("Waiting for broadcast");

          byte[] received = mUdpClient.Receive(ref mGroupEP);

          Logger.InfoFormat("Received {0} bytes", received.Length);
          OnReceived(received);
        } catch (Exception ex) {
          Logger.Error(ex.Message, ex);
        }
      }
    }

    protected void OnReceived(byte[] pData) {
      EventHandler<GenericEventArgs<byte[]>> handler = Received;
      if (handler != null) Received(this, new GenericEventArgs<byte[]>(pData));
    }

    public virtual ILogger Logger {
      get { return mLogger; }
      set { mLogger = value; }
    }

    #region Dispose

    private bool mDisposed = false;

    public void Dispose() {
      if (mDisposed) return;

      mDisposed = true;

      Close();
    }

    ~UDPBroadcastListener() {
      Dispose();
    }

    #endregion

  }
}

I am now getting extremely desperate. Please help. 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:13:38+00:00Added an answer on May 13, 2026 at 6:13 am

    You could try investigating with TCPView (It shows UDP as well) to see if anything shows up on the production server. Check out “Troubleshooting Windows Firewall settings“, although this is for XP and I doubt your production server is XP, but it may be helpful anyway. See the netstat example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UDP broadcast of some data. I'm able to open the following
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I have the following requirements for an application that many people will be using
This following is a straightforward IPv4 UDP broadcast, followed by listening on all interfaces.
For the following I'm assuming one network card. I have a component of my
I am messing around with a UDP listener and the TAP. I have a
any help would be appreciated. Im developing a udp connection and i have a
I have the following application which get launched as below: Runtime.getRuntime().exec(java -cp /var/dist/Test.jar System.V
I have both a client and server application using UDP port 25565. In order
in my application i have a server that listen in more than one udp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.