Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

Socket.h

Go to the documentation of this file.
00001 ///////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file       ClientSocket.cpp
00003  *  \brief      Definition of the Socket class for communicating.
00004  *
00005  *              The socket communications classes are based on the tutorial entitled
00006  *              "Linux Socket Programming In C++" by Rob Tougher on the Linux Gazette
00007  *              website. ( http://linuxgazette.net/issue74/tougher.html )
00008  *
00009  *  \author     Scott A. Kowalchuk
00010  *  \date       2006/11/29
00011  */////////////////////////////////////////////////////////////////////////////////////////////
00012 /*
00013  * \Status
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                 // Server initialization
00050                 bool create();
00051                 bool bind ( const int port );
00052                 bool listen() const;
00053                 bool accept ( Socket& ) const;
00054 
00055                 // Client initialization
00056                 bool connect ( const std::string host, const int port );
00057 
00058                 // Data Transimission
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

Generated on Wed Sep 5 12:54:25 2007 for DSACSS Operational Code by  doxygen 1.3.9.1