I'm more of a php programmer, not c#, but bear with me.
I have an application that connects with an API that sends push messages from time to time. It uses long polling as the mechanism. I've looked into using signalR for this, but all the examples show the server pushing the messages. I want the server to recieve the messages via longpolling. Does anyone know how to do this?
Yes. Just start request to the remote endpoint and wait for the response. When you have have processed the response, start again. It's as simple as that.
public async Task LongPoll(Uri remoteEndPoint)
{
for(;;)
{
string data;
using(var wc=new WebClient())
{
data = await wc.DownloadStringTaskAsync(remoteEndPoint);
}
Process(data);
}
}
I've ignored cancellation here, but you'll need to think about how polling ends if you ever want to terminate your app gracefully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With