I can't create server application in RakNet ( C++ )

319 views Asked by At

I'm trying create server application in C++ using RakNet. When i try following code :

#include <stdio.h>
#include "RakPeerInterface.h"

#define MAX_CLIENTS 10
#define SERVER_PORT 60000


int main(void)
{
    char str[512];
    RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
    bool isServer;

    printf("(C) or (S)erver?\n");
    gets(str);
    if ((str[0] == 'c') || (str[0] == 'C'))
    {
        SocketDescriptor sd;
        peer->Startup(1, &sd, 1);
        isServer = false;
    }
    else {
        SocketDescriptor sd(SERVER_PORT, 0);
        peer->Startup(MAX_CLIENTS, &sd, 1);
        isServer = true;
    }


    // TODO - Add code body here

    RakNet::RakPeerInterface::DestroyInstance(peer);

    return 0;
}

Compiler giving this errors :

Error image

I guess i set up RakNet successfully What is missing ?

1

There are 1 answers

0
Gibbon On BEST ANSWER

Well, one that that seems to be missing - if you are using the RakNet SocketDescriptor object is the "RakNet::" part to elt it know which namespace to use?

You have it on the PeerInterface section, but then have not used it on the SocketDescriptor

Also the RakNet socket descriptors are part of the "#include "RakNetTypes.h"" as far as I remember.. which also seems to be missing.. so unless youre using other SocketDescriptors .. that may also be needed :o

Missed the "Gets" part too - there is header for that under "#include "Gets.h"" within Raknet as well