00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef CClientTCPSocket_H
00029 #define CClientTCPSocket_H
00030
00031 #include <mrpt/config.h>
00032 #include <mrpt/system/os.h>
00033 #include <mrpt/utils/utils_defs.h>
00034 #include <mrpt/utils/CStream.h>
00035
00036 namespace mrpt
00037 {
00038 namespace utils
00039 {
00040 class CServerTCPSocket;
00041 class CMRPTMessage;
00042
00046 class MRPTDLLIMPEXP CClientTCPSocket : public CStream
00047 {
00048 friend class CServerTCPSocket;
00049
00050 protected:
00051
00052 #ifdef MRPT_OS_WINDOWS
00053
00055 unsigned int m_hSock;
00056 #endif
00057
00058 #ifdef MRPT_OS_LINUX
00059
00061 int m_hSock;
00062
00063 #endif
00064
00067 std::string m_remotePartIP;
00068
00071 unsigned short m_remotePartPort;
00072
00073
00078 size_t Read(void *Buffer, size_t Count);
00079
00085 size_t Write(const void *Buffer, size_t Count);
00086
00088 std::string getLastErrorStr();
00089
00090 public:
00094 CClientTCPSocket( );
00095
00098 ~CClientTCPSocket( );
00099
00105 void connect(
00106 const std::string &remotePartAddress,
00107 unsigned short remotePartTCPPort );
00108
00111 bool isConnected();
00112
00115 void close();
00116
00120 void sendString( const std::string &str );
00121
00124 size_t Seek(long Offset, CStream::TSeekOrigin Origin = sFromBeginning)
00125 {
00126 MRPT_TRY_START
00127 MRPT_UNUSED_PARAM(Offset); MRPT_UNUSED_PARAM(Origin);
00128 THROW_EXCEPTION("This method has no effect in this class!");
00129 MRPT_TRY_END
00130 }
00131
00134 size_t getTotalBytesCount()
00135 {
00136 MRPT_TRY_START
00137 THROW_EXCEPTION("This method has no effect in this class!");
00138 MRPT_TRY_END
00139 }
00140
00143 size_t getPosition()
00144 {
00145 MRPT_TRY_START
00146 THROW_EXCEPTION("This method has no effect in this class!");
00147 MRPT_TRY_END
00148 }
00149
00158 size_t readAsync(
00159 void *Buffer,
00160 size_t Count,
00161 int timeoutStart_ms = -1,
00162 int timeoutBetween_ms = -1);
00163
00172 size_t writeAsync(
00173 const void *Buffer,
00174 size_t Count,
00175 int timeout_ms = -1 );
00176
00181 bool sendMessage(
00182 const CMRPTMessage& outMsg
00183 );
00184
00191 bool receiveMessage(
00192 CMRPTMessage& inMsg,
00193 unsigned int timeoutStart_ms = 100,
00194 unsigned int timeoutBetween_ms = 1000
00195 );
00196
00197 };
00198
00199 }
00200 }
00201 #endif