I.SOURCE
http://www.ogre3d.org/tikiwiki/-RakNethttp://www.jenkinssoftware.com/
II.USE(VER3.6.11)
新版4.0里这些地方有细微差别,见官方文档和源码。
1.引入#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "RakNetworkFactory.h"
2.创建与销毁
RakPeerInterface *peer = RakNetworkFactory::GetRakPeerInterface();
//! As client
peer->Startup(1, 30 , &SocketDescriptor(), 1);
peer->Startup(MAX_CLIENTS, 30 , &SocketDescriptor(SERVER_PORT,0), 1);
//! As server
peer->Startup(MAX_CLIENTS, 30 , &SocketDescriptor(SERVER_PORT,0), 1);
peer->SetMaximumIncomingConnections(MAX_CLIENTS);
do something...
//! destroy
client->Shutdown(300);
RakNetworkFactory::DestroyRakPeerInterface(peer);
3.working
while (1)


{
for (packet=peer->Receive(); packet; peer->DeallocatePacket(packet), packet=peer->Receive())

{
switch (packet->data[0])

{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
printf("Another client has disconnected.\n");
break;
case ID_REMOTE_CONNECTION_LOST:
printf("Another client has lost the connection.\n");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
printf("Another client has connected.\n");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
printf("Our connection request has been accepted.\n");
break;
case ID_NEW_INCOMING_CONNECTION:
printf("A connection is incoming.\n");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
printf("The server is full.\n");
break;
case ID_DISCONNECTION_NOTIFICATION:

if (isServer)
{
printf("A client has disconnected.\n");

} else
{
printf("We have been disconnected.\n");
}
break;
case ID_CONNECTION_LOST:

if (isServer)
{
printf("A client lost the connection.\n");

} else
{
printf("Connection lost.\n");
}
break;
default:
printf("Message with identifier %i has arrived.\n", packet->data[0]);
break;
}
}
}
II.CHEDAN
just do it
http://www.jenkinssoftware.com/raknet/manual/tutorialsample2.html
