сокеты — Как я могу принять RakNet Connecting запрос в C ++?

я хочу принять запрос клиента на подключение но я не знаю, как я могу это сделать.

enum GameMessages
{
ID_GAME_MESSAGE_1 = ID_USER_PACKET_ENUM + 1
};

using namespace std;
int main(void)
{
RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
bool isServer;
RakNet::Packet *packet;
RakNet::SocketDescriptor sd(SERVER_PORT, 0);
peer->Startup(MAX_CLIENTS, &sd, 1);
isServer = true;
if (isServer)
{
printf("Sunucu baslatiliyor.\n");
// We need to let the server accept incoming connections from the clients
peer->SetMaximumIncomingConnections(MAX_CLIENTS);
}
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");

// Use a BitStream to write a custom user message
// Bitstreams are easier to use than sending casted structures, and handle endian swapping automatically
RakNet::BitStream bsOut;
bsOut.Write((RakNet::MessageID)ID_GAME_MESSAGE_1);
bsOut.Write("Oyuna hosgeldin emmolu.");
peer->Send(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, packet->systemAddress, false);
}
break;
case ID_NEW_INCOMING_CONNECTION:
printf("Bir baglanti geliyor.\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;
case ID_GAME_MESSAGE_1:
{
RakNet::RakString rs;
RakNet::BitStream bsIn(packet->data, packet->length, false);
bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
bsIn.Read(rs);
printf("%s\n", rs.C_String());
}
break;
default:
printf("Message with identifier %i has arrived.\n", packet->data[0]);
break;
}
}
}RakNet::RakPeerInterface::DestroyInstance(peer);return 0;
}

Когда я пробую свою работу, это дает мне этот.

[ЖУРНАЛ]
сервер : Сервер запущен.
клиент : Отправил запрос на подключение к серверу.
сервер : Запрос от клиента на подключение к серверу.
сервер : Принять запрос клиента. (Что я пытаюсь сделать)

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]