D
D
durnevdanya2017-05-27 20:22:13
Game development
durnevdanya, 2017-05-27 20:22:13

Unity - Client | Node.js + Socket.io + Json - server == Possible and how to do it?

Hello. Now I plan to create a project on Unity. But before that, he only did single-player games. There was no experience with the server part. After reading on the Internet, I chose node.js + socket.io for realtime, and for data transfer like this = Json:

(On Game)

Tell Server: Player 1 Just Finished a Match, he has 123456 points, died 3 times,

(On Server)

Tell Game: Player 1 its updated.

Question - Which technology to transfer JSON data to choose? And, the most interesting question for me is - How and where to publish your backend so that everyone can play it, anyone?
Thanks

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
devalone, 2017-05-27
@durnevdanya

If the exchange with the server is not too frequent, then it may be normal, but in general json is hardly a good choice for the game, it still needs to be parsed, which can be very expensive in terms of resources for both the server and the client.
Why not pass raw data in its byte representation, i.e. package, where 32 bytes (or how many do you have) for the authorization key, 4 bytes for points and 4 more bytes for times?
You probably meant "where to place the server?"? If yes, then on any VDS, for 300 rubles you can buy with 1 core and 1024MB of RAM. The client will either contact directly by ip, or first resolve the domain name, the second option is better.

X
xmoonlight, 2017-05-27
@xmoonlight

Hosting Rating: VPS

T
tomatho, 2017-05-28
@tomatho

This is more of an answer to an answer.
Parsing JSON well is no more expensive than reading plain text.
It's just that not all JSON libraries are well optimized.
The only problem may be that the "package" in json is larger than the "raw" bytes.
That is, it will affect the requirement for the speed of the Internet connection.
However, usually the problem is not in speed, but in ping. But you can roughly estimate the required bandwidth.
In addition, you can use JSON at the prototyping stage.
But here "nothing lasts forever as a temporary solution" can creep in.
Another minus of JSON is that you need to write well error handling, and attempts to break your packet exchange protocol.
They can, for example, send gigabyte-sized JSON to your server, and your JSON library will fall.
Or send something else.
The problem with raw bytes is that you have to maintain their format on both sides.
Different versions of clients will either have to be blocked until they are updated to a new version, or they will have to write terrible footcloths to process raw bytes. Although JSON is of little help here.
And yet, I'm not sure if your code parsing raw bytes, taking into account byte order, will be faster than JSON.parse from under the hood of V8 (Node.js)

A
Alibek Beldinov, 2017-05-29
@Neuyazvimy1

Don't write your backend. It's a waste of time developing support, etc. Use a backend service. https://www.gamesparks.com/
And if you still want to write a backend. Please do not write your serializer as you were told above.
Use msgpack.org/index.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question