00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __Socket_H__
00021 #define __Socket_H__
00022
00023
00024 #include <sys/types.h>
00025 #include <sys/socket.h>
00026 #include <netinet/in.h>
00027 #include <netdb.h>
00028 #include <unistd.h>
00029 #include <string>
00030 #include <arpa/inet.h>
00031
00032 #include <iostream>
00033
00034 #include <string.h>
00035 #include <errno.h>
00036 #include <fcntl.h>
00037
00038
00039 const int MAXHOSTNAME = 200;
00040 const int MAXCONNECTIONS = 5;
00041 const int MAXRECV = 500;
00042
00043 class Socket
00044 {
00045 public:
00046 Socket();
00047 virtual ~Socket();
00048
00049
00050 bool create();
00051 bool bind ( const int port );
00052 bool listen() const;
00053 bool accept ( Socket& ) const;
00054
00055
00056 bool connect ( const std::string host, const int port );
00057
00058
00059 bool send ( const std::string ) const;
00060 int recv ( std::string& ) const;
00061
00062
00063 void set_non_blocking ( const bool );
00064
00065 bool is_valid() const { return m_sock != -1; }
00066
00067 private:
00068 int m_sock;
00069 sockaddr_in m_addr;
00070
00071 };
00072
00073
00074 #endif