Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET UDP socket code works in development, but not in production on IIS
    primarykey
    data
    text
    <p>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.</p> <p>The log4net logging also seems to only work in the Init() method, but not the thread (which is weird). But I have added some <code>File.AppendAllText</code>'s to the thread and it DOES seem to be executing, but as far as I can tell, it stops on the line <code>byte[] received = mUdpClient.Receive(ref mGroupEP);</code></p> <p>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.</p> <p>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.</p> <pre><code> public class UDPBroadcastListener { #region Members private ILogger mLogger = NullLogger.Instance; private readonly int mPort; private UdpClient mUdpClient; private IPEndPoint mGroupEP; public event EventHandler&lt;GenericEventArgs&lt;byte[]&gt;&gt; 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&lt;GenericEventArgs&lt;byte[]&gt;&gt; handler = Received; if (handler != null) Received(this, new GenericEventArgs&lt;byte[]&gt;(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 } } </code></pre> <p>I am now getting extremely desperate. Please help. :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload