Game Development Reference
In-Depth Information
In the IsoTilemap04 project you'll get an introduction to sending and receiving packets
over a network. The most important aspect to creating network packets is that the re-
ceiver must be able to identify the type of packet received by looking at a common
header data. Typically, and this is also what the Apple documentation recommends,
you define C structs with a common struct field as the first entry for each packet. The
NetworkPackets.h file defines the structs, as shown in Listing 14-25 .
Listing 14-25 . Defining Network Packets as C Structs in NetworkPackets.h
typedef enum
{
kPacketTypeScore = 1,
kPacketTypePosition,
} EPacketTypes;
typedef struct
{
EPacketTypes type;
} SBasePacket;
// the packet for transmitting a score variable
typedef struct
{
EPacketTypes type;
int score;
} SScorePacket;
// packet to transmit a position
typedef struct
{
EPacketTypes type;
CGPoint position;
} SPositionPacket;
You'll see that all packet structs have the EPacketTypes type field, and it's the
first field in each struct. This allows you to cast any packet to one of type
 
 
Search Nedrilad ::




Custom Search