Long polling from server side C #

I am more a php programmer, not C #, but I carry it with me.

I have an application that connects to an API that sends push messages from time to time. The mechanism uses a lengthy survey. I studied the use of signalR for this, but all the examples show that the server is pushing messages. I want the server to receive messages through longpolling. Does anyone know how to do this?

+4
source share
1 answer

Yes. Just send a request to the remote endpoint and wait for a response. When you have processed the answer, start over. It is so simple.

public async Task LongPoll(Uri remoteEndPoint)
{
    for(;;)
    {
        string data;
        using(var wc=new WebClient())
        {
            data = await wc.DownloadStringTaskAsync(remoteEndPoint);
        }
        Process(data);  
    }
}

, , , - .

+6

All Articles