-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer_main.cpp
More file actions
50 lines (42 loc) · 1.24 KB
/
Copy pathServer_main.cpp
File metadata and controls
50 lines (42 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Created by matteo on 22/01/20.
//
#include <iostream>
#include <thread>
#include "raknet/RakPeerInterface.h"
#include "raknet/RakSleep.h"
#include "Common.h"
using std::cout;
using std::endl;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
int main()
{
cout << "Starting Server"<<endl;
RakNet::RakPeerInterface * rakpeer=RakNet::RakPeerInterface::GetInstance();
RakNet::SocketDescriptor socketDescriptor(MYPORT, nullptr);
auto res=rakpeer->Startup(10,&socketDescriptor,1);
rakpeer->SetMaximumIncomingConnections(10);
rakpeer->SetTimeoutTime(5000,RakNet::UNASSIGNED_SYSTEM_ADDRESS);
if(res==RakNet::RAKNET_STARTED)
cout << "good"<<endl;
while(true)
{
static int count=0;
RakSleep(1000);
if(!count)
cout << "Connected clients: "<<rakpeer->NumberOfConnections()<<endl;
RakNet::Packet * p=rakpeer->Receive();
if(p)
{
cout <<"received "<<p->bitSize<<" bits -> \""<<p->data<<"\""<<endl;
}
rakpeer->DeallocatePacket(p);
count++;
count%=5;
}
rakpeer->Shutdown(300);
RakNet::RakPeerInterface::DestroyInstance(rakpeer);
return 0;
}
#pragma clang diagnostic pop