SocketUDP.hh

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // CERTI - HLA RunTime Infrastructure
00003 // Copyright (C) 2002-2005  ONERA
00004 //
00005 // This program is free software ; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public License
00007 // as published by the Free Software Foundation ; either version 2 of
00008 // the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful, but
00011 // WITHOUT ANY WARRANTY ; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this program ; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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     // Socket
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     // SocketUDP
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 } // namespace certi
00109 
00110 #endif // CERTI_SOCKET_UDP_HH

Generated on Thu Apr 30 15:53:50 2009 for CERTIDeveloperDocumentation by doxygen 1.5.5