00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef SOCKETUDP_H
00010 #define SOCKETUDP_H
00011
00012
00013
00014
00015 #include <iostream>
00016 #include <cstring>
00017 #include <string>
00018 #include <unistd.h>
00019 #include <fcntl.h>
00020
00021 #include "ComPlusPlus/Socket.h"
00022
00023 namespace compp {
00024
00029
00030
00031
00032
00033 class SocketUdp : public Socket {
00034
00035 private:
00036 void NewUdpSocket();
00037
00038 protected:
00039 std::string SocketAddress ;
00040 int SocketPort;
00041
00042
00043
00044 public:
00045 ~SocketUdp();
00046 SocketUdp();
00047 SocketUdp(const std::string & Addr, int port);
00048 SocketUdp( int port);
00049 SocketUdp ( struct sockaddr_in *saddr, int len, int fd ) ;
00050
00051
00052 void Bind ( const std::string & addr, int port);
00053 void Bind ( const int port );
00054
00055 bool Connect( const std::string &addr, const int port );
00056
00057 void SetSockOptBroadcast ( bool yesno ) ;
00058 void SetSockOptJoinMulticastGroup ( const std::string & group ) ;
00059 void SetSockOptWithdrawMulticastGroup ( const std::string & group ) ;
00060 void SetSockOptMulticastLoop ( bool val ) ;
00061 void SetSockOptMulticastTTL ( int val ) ;
00062
00063 int Write ( char *buf, int count ) ;
00064 int Write ( const std::string & buf ) ;
00065 int Writen ( const char *buf, int count ) ;
00066 int Writen ( const std::string & buf ) ;
00067
00068 int Sendto(const void *buf, size_t len, const std::string &host, int port);
00069 int Sendto(const void *buf, size_t len, const struct sockaddr_in &ad );
00070
00071 int Read ( char *buf, int count, std::string &host, int & port ) ;
00072 int Read ( std::string &buf, int count, std::string &host, int & port ) ;
00073 int Read ( std::string &buf, std::string &host, int & port ) ;
00074
00075 int Readn ( char *buf, int count ) ;
00076 int Readn ( std::string &buf, int count) ;
00077
00078 int Recvfrom(void *buf, int len, int flags, std::string &from, int *port);
00079
00080 };
00081 }
00082 #endif
00083
00084