root/oscpack/tags/release_1_0_2/examples/OscDump.cpp
| Revision 29, 2.5 kB (checked in by ross, 3 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /* |
| 2 | oscpack -- Open Sound Control packet manipulation library |
| 3 | http://www.audiomulch.com/~rossb/oscpack |
| 4 | |
| 5 | Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com> |
| 6 | |
| 7 | Permission is hereby granted, free of charge, to any person obtaining |
| 8 | a copy of this software and associated documentation files |
| 9 | (the "Software"), to deal in the Software without restriction, |
| 10 | including without limitation the rights to use, copy, modify, merge, |
| 11 | publish, distribute, sublicense, and/or sell copies of the Software, |
| 12 | and to permit persons to whom the Software is furnished to do so, |
| 13 | subject to the following conditions: |
| 14 | |
| 15 | The above copyright notice and this permission notice shall be |
| 16 | included in all copies or substantial portions of the Software. |
| 17 | |
| 18 | Any person wishing to distribute modifications to the Software is |
| 19 | requested to send the modifications to the original developer so that |
| 20 | they can be incorporated into the canonical version. |
| 21 | |
| 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 23 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 24 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 25 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
| 26 | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 27 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 28 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 29 | */ |
| 30 | |
| 31 | /* |
| 32 | OscDump prints incoming Osc packets. Unlike the Berkeley dumposc program |
| 33 | OscDump uses a different printing format which indicates the type of each |
| 34 | message argument. |
| 35 | */ |
| 36 | |
| 37 | |
| 38 | #include <iostream> |
| 39 | |
| 40 | #include "osc/OscReceivedElements.h" |
| 41 | #include "osc/OscPrintReceivedElements.h" |
| 42 | |
| 43 | #include "ip/UdpSocket.h" |
| 44 | #include "ip/PacketListener.h" |
| 45 | |
| 46 | |
| 47 | class OscDumpPacketListener : public PacketListener{ |
| 48 | public: |
| 49 | virtual void ProcessPacket( const char *data, int size, |
| 50 | const IpEndpointName& remoteEndpoint ) |
| 51 | { |
| 52 | std::cout << osc::ReceivedPacket( data, size ); |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | int main(int argc, char* argv[]) |
| 57 | { |
| 58 | if( argc >= 2 && strcmp( argv[1], "-h" ) == 0 ){ |
| 59 | std::cout << "usage: OscDump [port]\n"; |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | int port = 7000; |
| 64 | |
| 65 | if( argc >= 2 ) |
| 66 | port = atoi( argv[1] ); |
| 67 | |
| 68 | OscDumpPacketListener listener; |
| 69 | UdpListeningReceiveSocket s( |
| 70 | IpEndpointName( IpEndpointName::ANY_ADDRESS, port ), |
| 71 | &listener ); |
| 72 | |
| 73 | std::cout << "listening for input on port " << port << "...\n"; |
| 74 | std::cout << "press ctrl-c to end\n"; |
| 75 | |
| 76 | s.RunUntilSigInt(); |
| 77 | |
| 78 | std::cout << "finishing.\n"; |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 |
Note: See TracBrowser for help on using the browser.
