#pragma once /* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer * * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. * You have to aquire licenses for all used proprietary modules. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include #include #include #include #include #include #include #include #include #include #include namespace osgVisual { //////////////////////////////////////////////////////////// // Broadcaster // // Class definition for broadcasting a buffer to a LAN // class Broadcaster : public osg::Referenced { public : Broadcaster(); ~Broadcaster(); // Initialize Broadcaster and its socket. bool init(const short port_ = 0); // Set a recipient host. If this is used, the Broadcaster // no longer broadcasts, but rather directs UDP packets at // host. void setDestinationHost( const char *hostname ); // Send/broadcasts the buffer void transmitBuffer( const char* buffer, const unsigned int size ); private : SOCKET _so; // Socket-Handle bool _initialized; // Initialized Flag short _port; // Socketport SOCKADDR_IN saddr; // Datenstruktur zum Verwalten der SocketDaten der Protokollfamilie (Port, IP etc.) unsigned long _destinationAddress; // Destinationaddress WORD requestedWSAVersion; }; /////////////////////////////////////////////////////////// // Receiver // // Class definition for the recipient of a broadcasted message // class Receiver : public osg::Referenced { public : Receiver(); ~Receiver(); // Initialize Reciever and its socket. bool init( const short port_ ); /** * \brief Sync does a blocking wait to recieve next message * * Why max Datagram size of ~65000 bytes : http://www.erg.abdn.ac.uk/users/gorry/eg3567/inet-pages/udp.html * Good introduction into WSA sockets: http://www.htwm.de/~win/vorlesungen/sockets.pdf * * * @param writeInto_ : Stringstream to write socket data into */ void waitBlockingforSocketData( std::stringstream& writeInto_ ); private : SOCKET _so; // Socket-Handle SOCKADDR_IN saddr; char buffer[65000]; bool _initialized; // Initialized-Flag WORD requestedWSAVersion; }; } // END NAMESPACE