Click here to Skip to main content
15,748,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows application that is working as a udp listener, I am trying to make it as a web application(MVC). the udp listener is running in a continues loop listening to the port all the time. is there any tutorials that I can use to convert this to a web application?

What I have tried:

I do not know how to trigger the controller inside the loop
Updated 19-Jan-22 12:27pm

1 solution

You're going to have to go into more detail as to how you expect this app to work.

ASP.NET/MVC code (C#, VB.NET) runs entirely on the server, not the client. So, if your code is listening on a UDP port, it's the server that's doing the listening.

If you want examples of a UDP listener, you just have to Google for "C# udp listener".
Share this answer
Prachith Goonasekara 19-Jan-22 18:32pm    
Hi Dave, thanks for the reply, Actually the listening part works. When I call the listener method from the controller, the loop starts working. But only concern that I have is to show those data in the view.
Dave Kreskowiak 19-Jan-22 18:42pm    
Well, you picked a bad application type for that. The web server cannot push content to the clients. HTTP/HTTPS is a connect/request/response/disconnect paradigm. The client requests a page and the server responds with that page and forgets the client even exists.

You seem to be thinking in a single-user environment when you cannot do that in a web application. Web apps are multi-user (clients).

Think about it. If your server-side code makes a change to the data, how is the server going to be able to contact the client (or even which client to connect to) to send it the new page? Hint: it can't.

The server would have to update some kind of state information it holds onto, either in memory or in a database, and when the client requests a refreshed page, the server can send the updated data state.
Prachith Goonasekara 19-Jan-22 18:47pm    
Yeah! thanks, that's what I was thinking as well, as all the changes to the data is happening in the server side and the client doesn't know about it. And a refresh from the client would not help. Anyway, thanks. So for something like this, webapps are not the solution right. :)
Prachith Goonasekara 19-Jan-22 18:52pm    
Otherwise, update the dataset into a json file and direct that into the view
Dave Kreskowiak 19-Jan-22 18:53pm    
...which the client still has to request.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900