#28741 - Krakken - Fri Nov 05, 2004 7:08 am
Hi,
I'm making a multiplayer game. I've real lots and lots on serial communication over time and am working on a packeting system for multiplayer transfers.
So far, i've worked out a system. I'll explain it in a second and I just would like some feedback on optimising or improving the system; or even if it's any good for that matter.
System Overview
The system works on a set of packets to send data. Each packet can contain pretty much anything. It implements pretty reliable transfer but can only do one byte per transfer. I intend on syncing transfers to frames so 60 transfers can be made per second - therefore a total of 60 bytes from each person.
How It Works
It works by sending a header followed by a checksum and then the data with information attached to it. If there is a problem at any point the master will cancel the packet and re-transfer all the data.
A List of Features Needed For it to Work
Transfer Type
This indicates the type of transfer:
- 00: Header
- 01: CheckSum
- 02: Normal Data
- 03: Error/Resend Request
Packet ID
The ID of the packet so that the right data can be resent on error. Also, so the data is reconstructed into the correct place. Every struct/whatever has it's own packet ID.
Transfer Bytes
The amount of bytes that need transferring for the particular packet.
CheckSum
To verify data.
Data
The actual data to transfer.
The System Itself
The actual system works as follows.
The Packet Header
The header is a 16-bit short value which is layed out like follows:
F E D C B A 9 8 7 6 5 4 3 2 1 0
T T P P P P P P B B B B B B B B
T: Packet Type (2 bits) = 00 (see above for explanation)
P: Packet ID (6 bits)
B: Bytes to Transfer (8 bits)
The CheckSum
Following the header, all units send out a checksum for their data structure. The format is as follows:
F E D C B A 9 8 7 6 5 4 3 2 1 0
T T C C C C C C C C C C C C C C
T: Packet Type (2 bits) = 01 (see above for explanation)
C: CheckSum (14 bits)
The Data
The data is immediately sent after the CheckSum. It is contually sent until it reaches the specified size from the header. The format is as follows.
F E D C B A 9 8 7 6 5 4 3 2 1 0
T T P P P P P P D D D D D D D D
T: Packet Type (2 bits) = 02 (see above for explanation)
P: Packet ID (6 bits)
D: Data (8 bits)
The Error
When an error occures, the following is sent to the master.
F E D C B A 9 8 7 6 5 4 3 2 1 0
T T P P P P P P X X X X X X X X
T: Packet Type (2 bits) = 03 (see above for explanation)
P: Packet ID (6 bits)
X: N/A (8 bits)
The Communication Method
Only the master machine constructs headers it informs all slave units to create a CheckSum from "Packet ID" data of size "Bytes to Transfer". All units then send back their CheckSum to each other and the transfer begins.
When data is recieved, it is reconstructed in sequence into temporary storage. Then it is tested against the checksum and if there is a match the data is copied into the appropriate "Packet ID" structure for that player. If not, it returns an error message to the master.
If the master recieves an error command, it will restart the transfer.
I'm making a multiplayer game. I've real lots and lots on serial communication over time and am working on a packeting system for multiplayer transfers.
So far, i've worked out a system. I'll explain it in a second and I just would like some feedback on optimising or improving the system; or even if it's any good for that matter.
System Overview
The system works on a set of packets to send data. Each packet can contain pretty much anything. It implements pretty reliable transfer but can only do one byte per transfer. I intend on syncing transfers to frames so 60 transfers can be made per second - therefore a total of 60 bytes from each person.
How It Works
It works by sending a header followed by a checksum and then the data with information attached to it. If there is a problem at any point the master will cancel the packet and re-transfer all the data.
A List of Features Needed For it to Work
Transfer Type
This indicates the type of transfer:
- 00: Header
- 01: CheckSum
- 02: Normal Data
- 03: Error/Resend Request
Packet ID
The ID of the packet so that the right data can be resent on error. Also, so the data is reconstructed into the correct place. Every struct/whatever has it's own packet ID.
Transfer Bytes
The amount of bytes that need transferring for the particular packet.
CheckSum
To verify data.
Data
The actual data to transfer.
The System Itself
The actual system works as follows.
The Packet Header
The header is a 16-bit short value which is layed out like follows:
F E D C B A 9 8 7 6 5 4 3 2 1 0
T T P P P P P P B B B B B B B B
T: Packet Type (2 bits) = 00 (see above for explanation)
P: Packet ID (6 bits)
B: Bytes to Transfer (8 bits)
The CheckSum
Following the header, all units send out a checksum for their data structure. The format is as follows:
F E D C B A 9 8 7 6 5 4 3 2 1 0
T T C C C C C C C C C C C C C C
T: Packet Type (2 bits) = 01 (see above for explanation)
C: CheckSum (14 bits)
The Data
The data is immediately sent after the CheckSum. It is contually sent until it reaches the specified size from the header. The format is as follows.
F E D C B A 9 8 7 6 5 4 3 2 1 0
T T P P P P P P D D D D D D D D
T: Packet Type (2 bits) = 02 (see above for explanation)
P: Packet ID (6 bits)
D: Data (8 bits)
The Error
When an error occures, the following is sent to the master.
F E D C B A 9 8 7 6 5 4 3 2 1 0
T T P P P P P P X X X X X X X X
T: Packet Type (2 bits) = 03 (see above for explanation)
P: Packet ID (6 bits)
X: N/A (8 bits)
The Communication Method
Only the master machine constructs headers it informs all slave units to create a CheckSum from "Packet ID" data of size "Bytes to Transfer". All units then send back their CheckSum to each other and the transfer begins.
When data is recieved, it is reconstructed in sequence into temporary storage. Then it is tested against the checksum and if there is a match the data is copied into the appropriate "Packet ID" structure for that player. If not, it returns an error message to the master.
If the master recieves an error command, it will restart the transfer.