ionflux.org | Impressum

TCPSocket.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_TCPSOCKET
00002 #define IONFLUX_TOOLS_TCPSOCKET
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * TCPSocket.hpp                 TCP Socket class
00009  * ==========================================================================
00010  * 
00011  * This file is part of Ionflux Tools.
00012  * 
00013  * Ionflux Tools is free software; you can redistribute it and/or modify it 
00014  * under the terms of the GNU General Public License as published by the Free
00015  * Software Foundation; either version 2 of the License, or (at  your option)
00016  * any later version.
00017  * 
00018  * Ionflux Tools is distributed in the hope that it will be useful, but 
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00021  * for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with Ionflux Tools; if not, write to the Free Software Foundation, 
00025  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  * 
00027  * ========================================================================== */
00028 
00029 #include <string>
00030 #include <iostream>
00031 #include <sstream>
00032 #ifndef HAVE_WINSOCK
00033 #include <sys/socket.h>
00034 #include <netinet/in.h>
00035 #include <arpa/inet.h>
00036 #include <netdb.h>
00037 #else
00038 #include <winsock.h>
00039 #include <unistd.h>
00040 typedef int socklen_t;
00041 #endif
00042 #include "ionflux/Reporter.hpp"
00043 
00044 namespace Ionflux
00045 {
00046 
00047 namespace Tools
00048 {
00049 
00061 class TCPSocket
00062 {
00063     protected:
00065         Ionflux::Tools::Reporter log;
00067         std::string remoteHostName;
00073         std::string clientIP;
00075         int port;
00077         int theSocket;
00079         bool connected;
00081         bool bound;
00083         bool listening;
00085         struct sockaddr_in remoteHostAddress;
00087         struct sockaddr_in localHostAddress;
00089         struct hostent *remoteHostEntry;
00091         int listenQueue;
00092         
00093     public:
00095         static const int READ_BUFFER_SIZE;
00097         static const int DEFAULT_LISTEN_QUEUE;
00098         
00103         TCPSocket();
00104         
00112         TCPSocket(int initPort);
00113         
00121         TCPSocket(const std::string& initHost, int initPort);
00122         
00127         virtual ~TCPSocket();
00128         
00135         virtual bool resolve();
00136         
00143         virtual bool connect();
00144         
00149         virtual void close();
00150         
00157         virtual bool bind();
00158         
00169         virtual bool bind(unsigned int newAddress);
00170         
00179         virtual bool listen();
00180         
00193         virtual int accept(sockaddr_in &newAddr, socklen_t &newAddrSize);
00194         
00208         virtual bool accept(TCPSocket &newClientSocket);
00209         
00218         virtual bool readBytes(std::string& bytes);
00219         
00228         virtual bool sendBytes(const std::string& bytes);
00229         
00237         virtual void setRemoteHost(const std::string& newHost);
00238         
00245         virtual void setPort(int newPort);
00246         
00255         virtual void setListenQueue(int newListenQueue);
00256         
00266         virtual void setFD(int newFD);
00267         
00279         virtual void setConnectionState(bool newConnectionState);
00280         
00292         virtual void setBindingState(bool newBindingState);
00293         
00305         virtual void setListeningState(bool newListeningState);
00306         
00317         virtual void setClientIP(const std::string &newClientIP);
00318         
00325         virtual int getPort();
00326         
00334         virtual std::string getRemoteHost();
00335         
00342         virtual int getFD();
00343         
00353         virtual bool isConnected();
00354         
00361         virtual int getListenQueue();
00362         
00372         virtual bool isBound();
00373         
00383         virtual bool isListening();
00384         
00395         virtual std::string getClientIP();
00396         
00401         virtual Reporter &getLog();
00402 };
00403 
00405 
00406 }
00407 
00408 }
00409 
00413 #endif

Generated on Tue Mar 14 20:58:30 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6