0

我正在尝试使用 RakNet 在 C++ 中创建服务器应用程序。当我尝试以下代码时:

#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;
}

编译器给出此错误:

错误图片

我想我成功设置了 RakNet 缺少什么?

4

1 回答 1

0

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

于 2017-12-05T11:07:55.670 回答