Note that there are some explanatory texts on larger screens.

plurals
  1. POGeneric way to handle many types of messages
    primarykey
    data
    text
    <p>I'm working on a little client that interfaces with a game server. The server sends messages to the connected client over HTTP. Its relatively easy to parse the text messages coming into the client and form responses to send back.</p> <p>Now what I'm trying to figure out is how to break up the process. I want to have a thread receiving the messages, parsing them into some data object, and placing them into an "incoming" queue to be processed. Then another thread reads messages from this queue and processes them (the brains or AI of the client) and makes responses back to the server. </p> <p>I want to have the thread that watches the incoming data to do process the text (break up the messages, pull the important data out, etc.) so the AI thread doesn't have that overhead. But the problem is that the server can send a couple hundred different types of messages to the client (what the client can see, other players, if you are firing etc). I want to package this data into a neat little structure so the AI can handle it quickly, and the AI can be rewritten easily. </p> <p>But how do I write a function that can pull something off a queue and know what type of message it is (so I know what data is contained within the message)?</p> <p>Example messages:</p> <p><strong>ALIVE</strong> (tells you if you are alive) <br />It has only one data object, the current game time</p> <p><strong>DAM</strong> (tells if you are damaged) <br />Has a whole bunch of data, who damaged you, how much, what gun it is, if you can see them, etc.</p> <p>It is possible to make an object that can handle all of these different message types and be interpreted by a single function? Very few messages have common attributes, so I don't think inheriting or just making one really big message class would be very good...</p> <p>I'm not looking for a full solution here, just point me in the right direction and hopefully I'll be able to learn a bit on the way :-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload