- Home /
Server-Side Events with UnityHTTPWebRequests (text/event-stream)
Hello,
I'm trying to get a Server-Sent Event working with Unity, but with little luck. So far, this is the code that I have tried to get it to constantly listen and fetch for updates with:
public IEnumerator ListenForChanges(string uri)
{
UnityWebRequest req = UnityWebRequest.Get(uri);
req.SetRequestHeader("Accept", "text/event-stream");
var response = req.SendWebRequest();
while (!req.isDone)
{
Debug.Log("Text downloaded: " + req.downloadHandler.text);
yield return new WaitForSeconds(1);
}
}
But this doesn't seem to be working. I am able to get one response from the function, but after that I get no other responses. Is there any way that I am able to get this to work, so that it constantly checks for updates and is able to stream them to the game?
I'm using Firebase Database as the back end, from where I am getting the data.
Thank you very much in advance.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
why does UnityWebRequest want Dispose() ? 1 Answer
How to connect to hosted scene (Multiplayer) 2 Answers
Multiplayer Networking Problem in Android 0 Answers
Updating multiplayer map on joining 1 Answer