Merge pull request #5 from intothevoid/master
[KDIS.git] / KDIS / Examples / PDU / Bundle / KDIS.cpp
blob90869c919bcdbe517b57296afebb2972ee3e6b7b
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
34 This example shows how to use the PDU bundling features in KDIS.
35 If you are sending multiple PDU in a short time then bundling
36 them into a single datagram can help reduce bandwidth and increase performance.
37 Note: Not all systems support bundling.
39 Run the PDU_Factory2 example to see the output of this example, PDU_Factory1 does not support bundling.
40 *********************************************************************/
42 #include <iostream>
43 #include "KDIS/PDU/Bundle.h" // Our bundle class
44 #include "KDIS/Network/Connection.h"
45 #include "./EntityGenerator.h" // Generates random Entity State PDU's
47 using namespace std;
48 using namespace KDIS;
49 using namespace DATA_TYPE;
50 using namespace PDU;
51 using namespace ENUMS;
52 using namespace UTILS;
53 using namespace NETWORK;
55 #define PDU_COUNT 10
57 int main()
59 try
61 // Note: This address will probably be different for your network.
62 Connection myConnection( "192.168.3.255" );
64 // We have 2 ways we can use the Bundle.
67 // 1
68 // We can give it PDU data streams and it will concatenate them for us into a single packet.
70 // Create the bundle. Just a collection of random ESPDUs.
71 Bundle pduBundle;
72 for( int i = 0; i < PDU_COUNT; ++i )
74 pduBundle.AddPDU( EntityGenerator::GenerateEntity().Encode() );
77 // Now send the bundle
78 myConnection.Send( pduBundle.Encode() );
79 cout << "1: Sent Bundle, Size: " << pduBundle.GetLength() << endl;
82 // 2
83 // We can give it PDU pointers/references which will be encoded each time.
84 // We can then use this over time if we want to keep sending the PDU together.
85 pduBundle.ClearPDUs();
87 for( int i = 0; i < PDU_COUNT; ++i )
89 pduBundle.AddPDU( EntityGenerator::GenerateEntityRef() );
92 // Now send the bundle
93 myConnection.Send( pduBundle.Encode() );
95 cout << "2: Sent Bundle, Size: " << pduBundle.GetLength() << endl;
97 catch( exception & e )
99 cout << e.what() << endl;
102 return 0;