Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server - C#, Client - Flash, data exchange protocol

We are writing online multiplayer game in Flash wish .Net server side, we need duplex channel so communication is done using sockets.

Can you tell me some best practices about protocol/format of exchanging data between server and client? IMO one of good choise may be using JSON serialization.

like image 763
Lev Avatar asked Apr 28 '13 11:04

Lev


People also ask

What is TCP C?

TCP sockets are used for communication between a server and a client process. The server's code runs first, which opens a port and listens for incoming connection requests from clients. Once a client connects to the same (server) port, the client or server may send a message.


2 Answers

I think, JSON can be the best choice and let me explain why.

Firstly, JSON-serialized game traffic is ligth-weighted, because JSON notation is like "name : val", not like "<name> val </name>".

Secondly, JSON serialization is the most intuitive one for games. XML and XML-like notations are good for multiline data, but in-game variables' values are usually rather short (HP, mana, AP, damage, etc.) and can be discribed with one line.

Thirdly, Actionscript 3 (I hope, you won't write MMO in AS2) has got perfect tools for JSON decoding/encoding. XML-parsing tools are good too, but IMO, JSON's are better. Also, in Flash 11+, JSON operations are extremely optimized.

Fourthly, many high-load projects use cache-servers with MongoDB, and it's main format is BSON (Binary JSON), so using JSON in this case will simplify data communication between DB and everything else.

like image 183
JustLogin Avatar answered Oct 04 '22 13:10

JustLogin


It depends. Forget the involved technologies for a while and focus on your specific comm needs. Hope you don't mind if I explore a few related points as well.

  • Point-to-point (p2p) flow: We know this one - Duplex, as you mentioned.
  • p2p mode: Half- or Full-duplex? Will data be exchanged simultaneously, or it is always a message-response mechanism?
  • State: You may have code that will wait for a response, even if the major part of your exchange is asynchronous. Is the exchange absolutely async? sync? mixed? This point is tightly related to the previous one.
  • Transmission: Data bursts, or constant streams?
  • Bandwidth: How many bytes/sec do you expect to traffic around? Is it a considerable percent of your target network (wireless? mobile? hi-speed?)
  • Reliable/unreliable content: Does the loss of a data package tosses your client state in disarray? (This isn't a bad thing per se, just a spec.)

If your code needs any kind of synchronous content, then you may need a reply flow control on you code, and a Messaging structure of some sort where Messages have an ID and may have a Original Message ID to which they are a reply. This will help you control content even on async protocols. In this case, an easily maintanable protocol like JSON may be better, as @JustLogin mentioned.

Full-Duplex mean you be staging more data on your network/interpreter layer, and it probably will have to handle asynchronous communications.

If performance is a concern, and depending on your specifics, then proposals like the one made by @Viacheslav can be attractive. A custom protocol can be heavily optimized, at the cost of maintanability and portability (several languages have their own JSON interpreter, while custom interpreters may need to be implemented or encapsuled, adding layers to the process and thus lowering performance, or requiring code conversion.)

If you couldn't care less if a packet or two are lost, then UDP may be a viable solution. Less control than TCP means a lighter protocol, but you're never sure that the data reached the other side unless you implement your own control.

TL;DR version: I would stick to standard low-level protocols like JSON, even if they add some overhead.

like image 25
OnoSendai Avatar answered Oct 04 '22 13:10

OnoSendai