i found AdvertiseSystem in Raknet library.
// Description:
// Sends a one byte message ID_ADVERTISE_SYSTEM to the remote unconnected system.
// This will tell the remote system our external IP outside the LAN, and can be used for NAT punch through
//
// host: Either a dotted IP address or a domain name
// remotePort: Which port to connect to on the remote machine.
virtual void AdvertiseSystem(char *host, unsigned short remotePort)=0;
so i try this function. i'd like to create a introducer to list all server available. so the server called advertiseSystem function. here is my code to test the function
// the server called the advertise
int main()
{
RakServerInterface *pRakServer = RakNetworkFactory::GetRakServerInterface();
pRakServer->Start( 10, 0, 0, 60001 );
char key;
while( 1 )
{
if( kbhit() )
{
key = getch();
if( key == 'c' )
{
pRakServer->AdvertiseSystem( "192.168.0.27", 60000 );
}
if( key == 27 )
break;
}
}
RakNetworkFactory::DestroyRakServerInterface( pRakServer );
pRakServer = 0;
return 0;
}
and here is my introducer
// the introducer to list all server,
// for now i just want to know if the introducer received advertise packet
class ServerTest: public Multiplayer<RakServerInterface>
{
public:
ServerTest();
~ServerTest();
void Update();
private:
void ProcessUnhandledPacket( Packet *pPacket, unsigned char packetIdentifier, RakServerInterface *pRakServer );
void ReceiveAdvertisedSystem( Packet *pPacket, RakServerInterface *pRakServer );
private:
RakServerInterface *m_pRakServer;
};
ServerTest::ServerTest()
{
m_pRakServer = RakNetworkFactory::GetRakServerInterface();
m_pRakServer->Start( 10, 0, 0, 60000 );
}
ServerTest::~ServerTest()
{
m_pRakServer->Disconnect( 3000 );
RakNetworkFactory::DestroyRakServerInterface( m_pRakServer );
m_pRakServer = 0;
}
void ServerTest::Update()
{
ProcessPackets( m_pRakServer );
}
void ServerTest::ProcessUnhandledPacket( Packet *pPacket, unsigned char packetIdentifier, RakServerInterface *pRakServer )
{
}
void ServerTest::ReceiveAdvertisedSystem( Packet *pPacket, RakServerInterface *pRakServer )
{
printf( "Get an advertisedSystem from address:%u port%u",
pPacket->playerId.binaryAddress, pPacket->playerId.port );
}
int main()
{
ServerTest myServer;
while( !kbhit() )
{
myServer.Update();
}
return 0;
}
it did receive the advertise packet, but strange result occur. the server use port 60001, and introducer use port 60000 but the result of this, is the introducer received port 52685 in pPacket->playerId. so i can't introduce this server. why this is happening? shouldn't the introducer receive port 60001 instead? thx..