0

I have a web application that I want to extend by some functionality. The application should be notified via Udp datagram by a remote host, about events triggered by sensor devices.

I have set up the remote host successfully, and also managed to write a simple .NET console application that opens a UdpClient and gets the data via UdpClient.Receive() method onto the console.

Now I want to integrate the Udp interface into my web application hosted in IISExpress 10.0 Express. But it seems like the IIS doesn't let me receive Udp datagrams from a remote host. The UdpClient.Receive() Method just blocks forever. No exception, nothing.

I dont quite get what is the problem here. My console application is able to receive the data on the same port, so it cannot be a firewall/global system misconfiguration. And also when i send some Udp data from a local application to localhost, it works even in IIS. It just seems to block out the Udp traffic from the outer world.

I think, but this is only a guess, that it has something to do with the bindings configured in applicationhost.config. My application is currently only configured to accept http requests on port 5000, which probably leads to IIS only listening for TCP connections on port 5000, but not for UDP on any other port.

This is the code i use, which works great outside of IIS:

UdpClient client;
IPEndPoint local = new IPEndPoint(IPAddress.Any, 3636);
IPEndPoint remote = new IPEndPoint(IPAddress.Any, 0);
client = new UdpClient(remote);
byte[] bytes = client.Receive(ref remote);
Console.WriteLine(bytes.Length);

Any ideas what I could try to make it work?

TostMaster
  • 164
  • 2
  • 9
  • where do you put your above code? – Hopeless Dec 28 '20 at 14:51
  • This may be a firewall issue, there is a similar question on SO, you can refer to it: https://stackoverflow.com/questions/1904162/asp-net-udp-socket-code-works-in-development-but-not-in-production-on-iis – Ding Peng Dec 29 '20 at 05:16
  • @Hopeless this is code that would be in the ASP.NET Core app – TostMaster Dec 29 '20 at 07:23
  • @DingPeng Thanks, already read that, but im pretty sure thats not it. As i wrote, my .NET console applications outside of IIS can receive data on the same port. – TostMaster Dec 29 '20 at 07:25
  • @TostMaster that code looks like a service endpoint, you cannot simply put it anywhere in the asp.net core app. I think it must be put in some `IHostedService` or some loop to continuously listen for input requests. What I mean is it may not even run correctly so input requests will simply fail. It differs from the simple code context in a console app (which you tested out) – Hopeless Dec 29 '20 at 07:29

0 Answers0