00001 #ifndef TcpClient_h 00002 #define TcpClient_h 00003 00004 /* 00005 * (c) Onix Solutions. 00006 */ 00007 00008 #include <string> 00009 #include <vector> 00010 00011 #include "./FIXEngineDefines.h" 00012 #include "EngineException.h" 00013 00014 namespace FIXForge{ 00015 namespace Sockets{ 00016 00017 /** 00018 * Provides client connections for TCP network services. 00019 */ 00020 class FF_API TcpClient 00021 { 00022 public: 00023 /** 00024 * Initializes a new instance of the TcpClient class and connects to the specified port on the specified host. 00025 * 00026 * @param hostname The DNS name of the remote host to which you intend to connect (or its IP address). 00027 * @param port The port number of the remote host to which you intend to connect. 00028 * @param timeoutInMillisecons Timeout value in milliseconds. If 0 then the method blocks until some data is received. 00029 */ 00030 TcpClient(const std::string& hostname, int port, int timeoutInMillisecons = 0); 00031 00032 /// Initializes a new instance of the TcpClient class. 00033 TcpClient(); 00034 00035 /// Destructor. 00036 ~TcpClient(void); 00037 00038 /** 00039 * Connects to the specified port on the specified host. 00040 * 00041 * @param hostname The DNS name of the remote host to which you intend to connect (or its IP address). 00042 * @param port The port number of the remote host to which you intend to connect. 00043 * @param timeoutInMillisecons Timeout value in milliseconds. If 0 then the method blocks until some data is received. 00044 */ 00045 void connect(const std::string& hostname, int port, int timeoutInMillisecons = 0); 00046 00047 /// Closes the TCP connection. 00048 void close(); 00049 00050 /** 00051 * Sets a value that disables a delay when send or receive buffers are not full. 00052 * 00053 * When setTcpNoDelayOption is false, a TcpClient does not send a packet over the network until it has collected a significant amount of outgoing data. 00054 * Because of the amount of overhead in a TCP segment, sending small amounts of data is inefficient. 00055 * However, situations do exist where you need to send very small amounts of data or expect immediate responses from each packet you send. 00056 * Your decision should weigh the relative importance of network efficiency versus application requirements. 00057 */ 00058 void setNoDelay(bool setTcpNoDelayOption = true); 00059 00060 /// Gets a value that disables a delay when send or receive buffers are not full. 00061 bool getNoDelay() const; 00062 00063 /// Sends the given value. 00064 void send(const std::string& value); 00065 00066 /// Sends the given value. 00067 void send(const char* buffer, size_t bufferLength); 00068 00069 typedef std::vector<char> Bytes; 00070 00071 /* 00072 * Receives the data. 00073 * 00074 * @param timeoutInMillisecons Timeout value in milliseconds. If 0 then the method blocks until some data is received. 00075 */ 00076 const Bytes& receive(int timeoutInMillisecons = 0); 00077 00078 /** 00079 * Receives exactly the given number of bytes. 00080 * 00081 * @param numberOfBytesToReceive Number of bytes to received. 00082 * @param timeoutInMillisecons Timeout value in milliseconds. If 0 then the method blocks until all bytes are received. 00083 */ 00084 const Bytes& receive(size_t numberOfBytesToReceive, int timeoutInMillisecons = 0); 00085 00086 private: 00087 struct Impl; 00088 Impl* impl_; 00089 00090 bool isClosed_; 00091 }; 00092 00093 }}; 00094 #endif 00095
1.5.7.1