Merge pull request #5 from intothevoid/master
[KDIS.git] / KDIS / Examples / Logging / DIS_Logger_Record / KDIS.cpp
blob465c010a8b6462853ed1388d37f846fc2d1d0b60
1 /**********************************************************************
2 The following UNLICENSE statement applies to this example.
4 This is free and unencumbered software released into the public domain.
6 Anyone is free to copy, modify, publish, use, compile, sell, or
7 distribute this software, either in source code form or as a compiled
8 binary, for any purpose, commercial or non-commercial, and by any
9 means.
11 In jurisdictions that recognize copyright laws, the author or authors
12 of this software dedicate any and all copyright interest in the
13 software to the public domain. We make this dedication for the benefit
14 of the public at large and to the detriment of our heirs and
15 successors. We intend this dedication to be an overt act of
16 relinquishment in perpetuity of all present and future rights to this
17 software under copyright law.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 OTHER DEALINGS IN THE SOFTWARE.
27 For more information, please refer to <http://unlicense.org/>
28 *********************************************************************/
30 /*********************************************************************
31 For Further Information on KDIS:
32 http://p.sf.net/kdis/UserGuide
33 *********************************************************************/
35 #include <iostream>
36 #include <time.h>
37 #include "KDIS/Extras/DIS_Logger_Record.h"
38 #include "KDIS/Network/Connection.h" // A cross platform connection class.
40 using namespace std;
41 using namespace KDIS;
42 using namespace DATA_TYPE;
43 using namespace ENUMS;
44 using namespace UTILS;
45 using namespace NETWORK;
47 #define LOG_FILE "Log.txt"
49 int main()
51 try
54 // Note this address will probably be different for your network.
55 Connection conn( "192.168.3.255" );
57 KOCTET cBuffer[MAX_PDU_SIZE]; // Somewhere to store the data we receive.
59 // Create the DIS logger, we want to buffer the data so we are not constantly
60 // performing I/O.
61 DIS_Logger_Record DisLogger( LOG_FILE, false );
62 KUINT32 ui32StartTime = time( NULL );
64 while( true )
66 KINT32 i32Recv = 0;
68 i32Recv = conn.Receive( cBuffer, MAX_PDU_SIZE );
70 KDataStream s( cBuffer, i32Recv );
72 // Record the PDU.
73 KUINT32 ui32TimeStamp = time( NULL ) - ui32StartTime;
74 DisLogger.Record( ui32TimeStamp, s );
76 if( DisLogger.GetBufferSize() > MAX_PDU_SIZE )DisLogger.Save();
79 catch( exception & e )
81 cout << e.what() << endl;
82 return -1;
85 return 0;