forked from facebookarchive/RakNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacketLoggerTest.cpp
More file actions
97 lines (80 loc) · 2.75 KB
/
Copy pathPacketLoggerTest.cpp
File metadata and controls
97 lines (80 loc) · 2.75 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include "GetTime.h"
#include "Rand.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#include "Gets.h"
#include "PacketLogger.h"
#include <assert.h>
#include "Kbhit.h"
#ifdef _WIN32
#include "WindowsIncludes.h" // Sleep
#else
#include <unistd.h> // usleep
#endif
static const int NUM_PEERS=2;
RakNet::RakPeerInterface *rakPeer[NUM_PEERS];
RakNet::PacketLogger messageHandler[NUM_PEERS];
void PrintConnections(void);
int main(void)
{
int i;
for (i=0; i < NUM_PEERS; i++)
rakPeer[i]=RakNet::RakPeerInterface::GetInstance();
printf("Packet Logger Test.\n");
printf("Displays all packets being sent or received.\n");
printf("Overwrite PacketLogger::Log to render output into your own program.\n");
printf("Difficulty: Intermediate\n\n");
printf("Comma delimited log format:\n");
printf("1. Send or receive,\n");
printf("2. Raw (direct socket send) OR Ack (Acknowledgement) OR\nTms (Timestamped packet),\n");
printf("3. Message number,\n");
printf("4. Packet Number (Independent for send & receive).\n(Each Packet may contain multiple messages),\n");
printf("5. Packet ID (or a string for RPC calls),\n");
printf("6. Bits used by the message (does not include 2-4 byte RakNet header),\n");
printf("7. Time the message is sent,\n");
printf("8. Local System (binary IP followed by port),\n");
printf("9. Remote System (binary IP followed by port)\n\n");
int peerIndex;
// Initialize the message handlers
for (peerIndex=0; peerIndex < NUM_PEERS; peerIndex++)
{
rakPeer[peerIndex]->AttachPlugin(&messageHandler[peerIndex]);
rakPeer[peerIndex]->SetMaximumIncomingConnections(NUM_PEERS);
}
// Initialize the peers
for (peerIndex=0; peerIndex < NUM_PEERS; peerIndex++)
{
RakNet::SocketDescriptor socketDescriptor(60000+peerIndex,0);
rakPeer[peerIndex]->Startup(NUM_PEERS, &socketDescriptor, 1);
}
printf("Connecting two systems...\n\n");
messageHandler[0].LogHeader();
// Connect each peer to the prior peer
for (peerIndex=1; peerIndex < NUM_PEERS; peerIndex++)
{
rakPeer[peerIndex]->Connect("127.0.0.1", 60000+peerIndex-1, 0, 0);
}
#ifdef WIN32
Sleep(5000);
#else
usleep(5000*1000);
#endif
for (i=0; i < NUM_PEERS; i++)
RakNet::RakPeerInterface::DestroyInstance(rakPeer[i]);
printf("Press enter to continue.\n");
char temp[256];
Gets(temp,sizeof(temp));
return 1;
}