00001 #ifndef _TCP_SOCKET_H_ 00002 #define _TCP_SOCKET_H_ 00003 /* 00004 * Copyright (c) 2007, 2008, 2009, University of Karlsruhe (for members see AUTHORS file) 00005 * 00006 * ISC License 00007 * 00008 * Permission to use, copy, modify, and/or distribute this software for any 00009 * purpose with or without fee is hereby granted, provided that the above 00010 * copyright notice and this permission notice appear in all copies. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 00013 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 00014 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 00015 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 00016 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 00017 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 00018 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00019 * 00020 * Created by Manfred Kroehnert on 26.07.2008. 00021 * based on CUDPSocket from Pedram Azad and Kai Welke 00022 */ 00023 00027 // ***************************************************************** 00028 // includes 00029 // ***************************************************************** 00030 #ifdef WIN32 00031 #include <windows.h> 00032 #include <winsock.h> 00033 #else 00034 #include <netinet/in.h> 00035 #endif 00036 00037 #include <string> 00038 00039 // ***************************************************************** 00040 // defines 00041 // ***************************************************************** 00042 #ifdef WIN32 00043 #else 00044 #ifdef SOCKET 00045 #undef SOCKET 00046 #endif 00047 #define SOCKET int 00048 #define SOCKET_ERROR -1 00049 #define INVALID_SOCKET -1 00050 #endif 00051 00052 // ***************************************************************** 00053 // CTCPSocket 00054 // ***************************************************************** 00055 00056 class CTCPSocket 00057 { 00058 public: 00059 // constructor 00068 CTCPSocket(const std::string& address, int nPort, bool isServer = false, int nTimeoutMilliSec = 0); 00069 00070 // destructor 00071 ~CTCPSocket(); 00072 00073 00074 // public methods 00082 bool openSocket(); 00086 void closeSocket(); 00097 int send(const char *pData, int nSize) const; 00108 int send(const std::string& data) const; 00119 int receive(char *pBuffer, int nMaxSize); 00120 00129 bool setNonBlocking(int nTimeoutMilliSec); 00130 00136 bool isConnected(); 00137 00138 // public attributes 00139 const int PORT; 00140 private: 00141 00142 // private attributes 00143 sockaddr_in address; 00144 std::string remoteAddress; 00146 int timeout; 00147 const int LISTEN_BACKLOG; 00149 bool bInitialised; 00150 const bool IS_SERVER_SOCKET; 00152 SOCKET tcp_socket; 00153 SOCKET server_listen_socket; 00154 }; 00155 00156 #endif /* _NETWORK_H_ */
Generated on Sat Mar 10 20:00:14 2012 for IPSA by 1.5.8 |