I have a web service that performs some operations. When an event occurs I will like to notify the clients. The problem that I have is that I am able to connect from the client to the server but not the other way around because clients happen to be behind a NAT (router). Currently I am making a request every minute to check for notifications. It would be nice if I can have a technique where I could notify the clients faster without having to make so many unnecessary request.
Note:
The client is a c# console application and the server is a asp.net website.
(note if an event happens on the server I will like to notify all clients)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Use SignalR. This is Microsoft’s new library for abstracting out real time server-client connections and if your setup allows it, it supports the new WebSockets protocol.
Taken from asp.net website. The Client Code
var hubConnection = new HubConnection("http://www.contoso.com/");
IHubProxy stockTickerHubProxy = hubConnection.CreateHubProxy("StockTickerHub");
stockTickerHubProxy.On<Stock>("UpdateStockPrice",
stock => Console.WriteLine("Stock update for {0} new price {1}", stock.Symbol, stock.Price));
await hubConnection.Start();
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0