2008-09-03 23:57:56| 分类: net_RakNet | 标签: |举报 |字号大中小 订阅
SocketDescriptor
用于描述基本的IP/Port信息,RakPeer::Startup() 时使用。
struct SocketDescriptor
{
SocketDescriptor();
SocketDescriptor(unsigned short _port, const char *_hostAddress);
unsigned short port; // 端口号, 0 则系统自动分配
char hostAddress[32]; // IP地址,== "" 表示 INADDR_ANY
};
======================
SystemAddress
用于表示一个系统/节点(peer)的唯一ID(Unique identifier for a system),其实也是个IP/Port pair,不过与 SocketDescriptor 不同, typeof(binaryAddress) == uint。
struct RAK_DLL_EXPORT SystemAddress
{
unsigned int binaryAddress; // == inet_addr("aaa.bbb.ccc.ddd"),就是IP地址的uint32表示
unsigned short port; // 端口号
};
======================
NetworkID
暂时还不知道具体用来干啥的。
struct NetworkID
{
// Set this to true to use peer to peer mode for NetworkIDs.
// Obviously the value of this must match on all systems.
// True, and this will write the systemAddress portion with network sends. Takes more bandwidth, but NetworkIDs can be locally generated
// False, and only localSystemAddress is used.
static bool peerToPeerMode;
// In peer to peer, we use both systemAddress and localSystemAddress
// In client / server, we only use localSystemAddress
SystemAddress systemAddress;
unsigned short localSystemAddress;
NetworkID& operator = ( const NetworkID& input );
....
};
======================
Packet
每次 Recv() 都是得到一个 struct Packet。
/// This represents a user message from another system.
struct Packet
{
/// Server only - this is the index into the player array that this systemAddress maps to
SystemIndex systemIndex;
/// The system that send this packet.
SystemAddress systemAddress;
/// The length of the data in bits
BitSize_t bitSize;
/// The data from the sender
unsigned char* data;
...
};
评论