chore: structure basic
[KDIS.git] / Examples / Network / ConnectionAddressFilter / KDIS.cpp
blobc97c9825bd8dae149968065177100d3ad2885f54
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 is based on PDU_Factory2 example however it shows how the
35 ConnectionAddressFilter can be used to block/allow particular IP addresses.
36 If you want to test this you will need an other machine generating DIS to see the filter in action.
37 *********************************************************************/
39 #include <iostream>
40 #include "KDIS/Extras/PDU_Factory.h"
41 #include "KDIS/Network/Connection.h"
42 #include "KDIS/Network/ConnectionAddressFilter.h"
44 using namespace std;
45 using namespace KDIS;
46 using namespace PDU;
47 using namespace NETWORK;
49 int main()
51 try
53 // Note this multi cast address will probably be different for your network however
54 // port 3000 is the assigned number by IANA(Internet Assigned Numbers Authority) for DIS simulations.
55 Connection conn( "192.168.3.255" );
57 // Create the filter and set it up so it only allows our test machine through.
58 ConnectionAddressFilter filter( ConnectionAddressFilter::AllowAddressesInFilterList ); // Only allow address we add through.
59 //ConnectionAddressFilter filter( ConnectionAddressFilter::BlockAddressesInFilterList ); // Block the address we add and allow all others through.
61 filter.AddAddress( "192.168.3.241" ); // This should be the address of your other DIS machine
62 //filter.AddAddress( "192.168.3.124" ); // Add an other machine?
64 // Add our filter
65 conn.AddSubscriber( &filter );
67 while( true )
69 try
71 unique_ptr<Header> pHeader = conn.GetNextPDU();
72 if( pHeader.get() )
74 cout << pHeader->GetAsString() << endl;
77 catch( exception & e )
79 // KDIS error, should be safe to carry on.
80 cout << e.what() << endl;
84 catch( exception & e )
86 // Socket/Connection error, better stop.
87 cout << e.what() << endl;
90 return 0;