Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef INCLUDED_UDPSOCKET_H
00031 #define INCLUDED_UDPSOCKET_H
00032
00033 #ifndef INCLUDED_NETWORKINGUTILITIES_H
00034 #include "NetworkingUtils.h"
00035 #endif
00036
00037 #ifndef INCLUDED_IPENDPOINTNAME_H
00038 #include "IpEndpointName.h"
00039 #endif
00040
00041
00042 class PacketListener;
00043 class TimerListener;
00044
00045 class UdpSocket;
00046
00047 class SocketReceiveMultiplexer{
00048 class Implementation;
00049 Implementation *impl_;
00050
00051 friend class UdpSocket;
00052
00053 public:
00054 SocketReceiveMultiplexer();
00055 ~SocketReceiveMultiplexer();
00056
00057
00058
00059
00060 void AttachSocketListener( UdpSocket *socket, PacketListener *listener );
00061 void DetachSocketListener( UdpSocket *socket, PacketListener *listener );
00062
00063 void AttachPeriodicTimerListener( int periodMilliseconds, TimerListener *listener );
00064 void AttachPeriodicTimerListener(
00065 int initialDelayMilliseconds, int periodMilliseconds, TimerListener *listener );
00066 void DetachPeriodicTimerListener( TimerListener *listener );
00067
00068 void Run();
00069 void RunUntilSigInt();
00070 void Break();
00071 void AsynchronousBreak();
00072 };
00073
00074
00075 class UdpSocket{
00076 class Implementation;
00077 Implementation *impl_;
00078
00079 friend class SocketReceiveMultiplexer::Implementation;
00080
00081 public:
00082
00083
00084
00085 UdpSocket();
00086 virtual ~UdpSocket();
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 IpEndpointName LocalEndpointFor( const IpEndpointName& remoteEndpoint ) const;
00097
00098
00099
00100 void Connect( const IpEndpointName& remoteEndpoint );
00101 void Send( const char *data, int size );
00102 void SendTo( const IpEndpointName& remoteEndpoint, const char *data, int size );
00103
00104
00105
00106
00107 void Bind( const IpEndpointName& localEndpoint );
00108 bool IsBound() const;
00109
00110 int ReceiveFrom( IpEndpointName& remoteEndpoint, char *data, int size );
00111 };
00112
00113
00114
00115
00116
00117
00118
00119 class UdpTransmitSocket : public UdpSocket{
00120 public:
00121 UdpTransmitSocket( const IpEndpointName& remoteEndpoint )
00122 { Connect( remoteEndpoint ); }
00123 };
00124
00125
00126 class UdpReceiveSocket : public UdpSocket{
00127 public:
00128 UdpReceiveSocket( const IpEndpointName& localEndpoint )
00129 { Bind( localEndpoint ); }
00130 };
00131
00132
00133
00134
00135
00136 class UdpListeningReceiveSocket : public UdpSocket{
00137 SocketReceiveMultiplexer mux_;
00138 PacketListener *listener_;
00139 public:
00140 UdpListeningReceiveSocket( const IpEndpointName& localEndpoint, PacketListener *listener )
00141 : listener_( listener )
00142 {
00143 Bind( localEndpoint );
00144 mux_.AttachSocketListener( this, listener_ );
00145 }
00146
00147 ~UdpListeningReceiveSocket()
00148 { mux_.DetachSocketListener( this, listener_ ); }
00149
00150
00151 void Run() { mux_.Run(); }
00152 void RunUntilSigInt() { mux_.RunUntilSigInt(); }
00153 void Break() { mux_.Break(); }
00154 void AsynchronousBreak() { mux_.AsynchronousBreak(); }
00155 };
00156
00157
00158 #endif