I plan on implementing chat and team features in my next game. How do I push a chat update to a player? Should I make the device query the web service regularly?
I plan on using SQL Server, with an IIS Web Service. So, for example, once a player types a message on the device, the device using the web service sends it to the database. However, how do I ensure other users on other devices see this new chat?
Thanks. However, my game does not consist of people playing each other simultaneously. It is a match 3 game and the players don’t play directly against each other. People will be leaving comments at different times in the chat. Like in the Harry Potter match 3 game I am on a team. In the chat people leave comments at different times, even when I am away from the game. My device is not networked to their device or being a host.
One way to do it is to write a server side application that takes SOME request from the players and shoots back some Json. You can decode json into structs using JsonUtility, there are limitations, though.
You can request data from the server using UnityWebRequest:
Which allows you to implement Get/Post/Head and other usual stuff.
The server side language could be anything that can implement such event.
Php used to be a popular choice, Flask + Python can be used as well, and there’s an option to write it in C#, I believe.
That’s the easy way. Basically the game would poll the server for new information.
If you want to PUSH the data you’ll need to implement a server-side app that maintains connection with players continuously. This is kinda similar to implementing a MJPEG generator in Python.
It is also possible to write a Unity application for that which would act like a headless server and run continously. That can be done using Mirror framework.