Using packets in context
Having a packet through which data can be send and received is all well and good
but the problem remains of exactly what to do when that data is received.
You’ve received the number 8 from the other client? That’s great, but seeing
as this isn’t a game about receiving the number 8 from another client, a little
more work needs to be done to let a client know what it’s supposed to do with a
number 8.
I created a method in the client class which takes in a data packet received and
handles it like so:
I then created the send method, which ensures that when data is sent, it does so
in the order it needs to be received.
- Send the type
- Send the data
- Send the unit id if needed