Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

Commented Unassigned: Maintaining Twitter Stream [2433]

$
0
0
Thanks for the great job you'v done.

I'm facing unreported disconnection in the FilteredSteam.
According to this [page](https://dev.twitter.com/streaming/overview/connecting), such stalls must be expected from Twitter Streaming API, and in the same page, a best practice is provided to handle such stalls in witch:
- A newline is sent by the API every 30 seconds as a heartbeat to maintain the connection.
- If no heartbeat signal is received for 90 second, the app must disconnect and reconnect immediately according to the backoff strategies provided in the same page.

I dug into the source code and I found that streaming loop is handled in the class StreamResultGenerator, but I didn't find that best practice there.
My question is:
Is this best practice to maintain the connection with Streaming API is handled somewhere else or this is a feature yet to be provided ?

Thanks again.
Comments: ** Comment from web user: linvi **

Hi,

Yes, the StreamResultGenerator class is starting to get old and such behavior have not yet been implemented.
I know Twitter reliability has been decreasing the last months but I have no plan to change that in the coming release (0.9.5.0).

Feel free to change the code, here is a snippet to start:

``` C#
// Line 122 replace : "string jsonResponse = await _currentReader.ReadLineAsync();" by the following
string jsonResponse = null;
var readJsonResponseTask = _currentReader.ReadLineAsync();
var resultingTask = await TaskEx.WhenAny(readJsonResponseTask, TaskEx.Delay(30000));
if (resultingTask == readJsonResponseTask)
{
jsonResponse = readJsonResponseTask.Result;
}
else
{
StopStream(new TimeoutException("Timeout!"));
}
```

And handle the StreamStopped event of the FilteredStream in your code to restart it.

Regards,
Linvi


Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>