source: osgVisual/include/cluster/dataIO_clusterUDP_Transmission.h @ 42

Last change on this file since 42 was 32, checked in by Torben Dannhauer, 15 years ago

Adding first version of osgVisual!!

File size: 2.9 KB
Line 
1#pragma once
2/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer
3 *
4 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
10 * You have to aquire licenses for all used proprietary modules.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * OpenSceneGraph Public License for more details.
16*/
17
18
19#include <osg/Referenced>
20#include <osg/Notify>
21
22#include <stdio.h>
23#include <fcntl.h>
24#include <sys/types.h>
25#include <string.h>
26#include <winsock2.h>
27#include <stdio.h>
28#include <string.h>
29#include <iostream>
30#include <sstream>
31
32
33namespace osgVisual
34{
35
36////////////////////////////////////////////////////////////
37// Broadcaster
38//
39// Class definition for broadcasting a buffer to a LAN
40//
41
42class Broadcaster : public osg::Referenced
43{
44public :
45        Broadcaster();
46        ~Broadcaster();
47
48        // Initialize Broadcaster and its socket.
49        bool init(const short port_ = 0);
50
51        // Set a recipient host.  If this is used, the Broadcaster
52        // no longer broadcasts, but rather directs UDP packets at
53        // host.
54        void setDestinationHost( const char *hostname ); 
55
56        // Send/broadcasts the buffer
57        void transmitBuffer( const char* buffer, const unsigned int size );
58
59private :
60
61    SOCKET _so; // Socket-Handle
62
63    bool _initialized;  // Initialized Flag
64    short _port;                // Socketport
65
66    SOCKADDR_IN saddr;  // Datenstruktur zum Verwalten der SocketDaten der Protokollfamilie (Port, IP etc.)
67
68    unsigned long _destinationAddress;  // Destinationaddress
69
70        WORD requestedWSAVersion;
71};
72
73///////////////////////////////////////////////////////////
74// Receiver
75//
76// Class definition for the recipient of a broadcasted message
77//
78class Receiver : public osg::Referenced
79{
80 public :
81
82        Receiver();
83        ~Receiver();
84
85        // Initialize Reciever and its socket.
86        bool init( const short port_ );
87
88        /**
89         * \brief Sync does a blocking wait to recieve next message
90         *
91         * Why max Datagram size of ~65000 bytes : http://www.erg.abdn.ac.uk/users/gorry/eg3567/inet-pages/udp.html
92         * Good introduction into WSA sockets: http://www.htwm.de/~win/vorlesungen/sockets.pdf
93         *
94         *
95         * @param writeInto_ : Stringstream to write socket data into
96         */ 
97        void waitBlockingforSocketData( std::stringstream& writeInto_ );
98
99 private :
100    SOCKET _so; // Socket-Handle
101    SOCKADDR_IN saddr;
102        char buffer[65000];
103    bool _initialized;  // Initialized-Flag
104        WORD requestedWSAVersion;
105};     
106
107}       // END NAMESPACE
Note: See TracBrowser for help on using the repository browser.