rdavisau / sockets-for-pcl

Cross-platform socket API for Xamarin iOS/Android/Forms, Xamarin.Mac/MonoMac, Windows Phone 8/8.1, Windows Store and Windows Desktop.
MIT License
223 stars 76 forks source link

Sockets and UWP Background Tasks #95

Open vbisbest opened 8 years ago

vbisbest commented 8 years ago

Do you have any support or instructions on how to keep sockets running while a UWP app is in the background? I see this article but it looks like this may need to happen down in your code? https://msdn.microsoft.com/en-us/windows/uwp/networking/network-communications-in-the-background

Thoughts? Thank you

rdavisau commented 7 years ago

Howdy,

I think this may be a fairly complicated, the challenge will be coming up with an api that will work for all the platforms concerned. It might be possible to enscapsulate most of the functionality behind a background enabled option for the socket and two methods the user would need to call from the native platform - unless already abstracted by something like Xamarin Forms - (e.g. WillSuspend and WillResume), but more investigation needed to confirm that. The implementation would be non trivial but as you say it definitely needs to be kicked off in my code.

I take it you are using the package I uploaded manually on UWP with no problems now?

vbisbest commented 7 years ago

Thanks Ryan. Yes is extremely complicated and I still don't even get it. I am running from your source code now.

Ray

rdavisau commented 7 years ago

Ok - glad I'm not the only one that thinks that explanation of steps was pretty wild.

I don't know what your use case is but maybe allowing disconnect and then resuming the connection with a background task might work? It may also end up subject to some of the same constraints though.

vbisbest commented 7 years ago

That wont work in my case. I am connected to a server that is streaming data constantly and it requires a keep alive from my app every few seconds. Think of it like a live stock ticker. When the app gets minimized, the app gets suspended and then the server disconnects after a few seconds since it did not get the keep alive.