Interface event sources ( aka server sent events ) with www class

Dear all!

Is it possible to interface an event source (( HTML Standard ) ) with the built in WWW class ? It would be very nice to have this technology available to get informed about server state changes on the client side. Has someone experience with this ? Can someone point me to the right starting point or provide any code snippets?

Thanks in advance!

No, it’s not possible with Unity’s WWW class. The WWW class is for simple web requests only. Server sent events requires a protocol which allows to keep the connection open and to receive partial stream data. The HTTP protocol is complete request-> response oriented. There are extensions (Keep alive connections) or sub protocols (like WebSockets) which allow to keep the connection open and use it as a communication channel. However this is not possible with the WWW class. It’s completely request oriented. It is possible to do “long polling” with the WWW class, but watch out for the timeout.

Depending on what kind of server you actually use it might be better to use a custom TCP connection. Though it also depends on which platform you want to target. For example in a webGL build you can only use WebSockets. Unity’s new network system can be used as it uses WebSockets when you build for WebGL.

For more details see Networking