00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef CERTI_SOCKET_UDP_HH
00021 #define CERTI_SOCKET_UDP_HH
00022
00023 #include "Socket.hh"
00024
00025 #ifdef _WIN32
00026 #ifndef _WINSOCK2API_
00027 #ifndef _WINSOCKAPI_
00028 #include <winsock2.h>
00029 #endif
00030 #endif
00031 #else
00032 #include <sys/socket.h>
00033 #include <netdb.h>
00034 #endif
00035
00036 #define BUFFER_MAXSIZE 2000
00037
00038 namespace certi {
00039
00040 class CERTI_EXPORT SocketUDP : public Socket
00041 {
00042 public :
00043 SocketUDP();
00044 virtual ~SocketUDP();
00045
00046
00047 virtual void send(const unsigned char *, size_t)
00048 throw (NetworkError, NetworkSignal);
00049
00050 virtual void receive(void * Message, unsigned long Size)
00051 throw (NetworkError, NetworkSignal);
00052
00053 virtual bool isDataReady() const ;
00054
00055 #ifdef _WIN32
00056 SOCKET returnSocket();
00057 #else
00058 int returnSocket();
00059 #endif
00060 virtual unsigned long returnAdress() const ;
00061
00062 virtual void close();
00063
00064
00065 virtual void createConnection(const char *server_name, unsigned int port)
00066 throw (NetworkError);
00067
00068 void createUDPServer(unsigned int port)
00069 throw (NetworkError, NetworkSignal);
00070
00071 void attach(int socket_ouvert, unsigned long Adresse, unsigned int port)
00072 throw (NetworkError, NetworkSignal);
00073
00074 unsigned int getPort() const ;
00075 unsigned long getAddr() const ;
00076
00077 private:
00078 void setPort(unsigned int port);
00079
00080 int bind();
00081 int open();
00082
00083 bool PhysicalLink ;
00084
00085 #ifdef _WIN32
00086 SOCKET _socket_udp;
00087 #else
00088 long _socket_udp;
00089 #endif
00090 struct sockaddr_in sock_local ;
00091
00092 struct sockaddr_in sock_source ;
00093 char *Addr_Source ;
00094 unsigned int Port_Source ;
00095 struct sockaddr_in sock_distant ;
00096 struct hostent * hp_distant ;
00097
00098 int _sock_local_length ;
00099 bool _est_init_udp ;
00100
00101 ByteCount_t SentBytesCount ;
00102 ByteCount_t RcvdBytesCount ;
00103
00104 unsigned long BufferSize ;
00105 char Buffer[4096] ;
00106 };
00107
00108 }
00109
00110 #endif // CERTI_SOCKET_UDP_HH