I would like to send data from a server to a client, continuously (streaming), without the need for the client to continuously loop through and check for any data. I think I am right in believing this is the observer design pattern? How is this possible?
Could someone provide me with a list of things I can google? How is the observer pattern aspect implemented?
Thanks
The observer design pattern is slightly different from what you’re describing:
Note that each observer gets notified by the “observable” object; so if you have a server that’s continuously streaming data, then would you expect the server to “notify” you and what would you expect the server to notify you of? Every packet it sends you? Every chunk of packets?
In short: no, you can’t implement the observer pattern on a client/server application. There is no (easy) way for a server to invoke a notify method on your client app and if your client gets disconnected, then it won’t unregister from the observable.
So back to your question… you’re limited by the architecture: blocking sockets (tcp/udp) all work by blocking until you receive data. Once you receive data, you have to loop through and call receive again in order to continuously get more data. An alternative is to use asynchronous sockets:
Asynchronous socket communication is probably as close you will get to the observer pattern. Furthermore, you want to use the UDP protocol because you have streaming data and UDP is specifically designed for streaming data. If you don’t want to miss any packets (due to the unreliability of UDP), then you can use reliable UDP.