#ifndef _OFX_TCP_CLIENT_
#define _OFX_TCP_CLIENT_

#include "ofConstants.h"
#include "ofxThread.h"
#include "ofxTCPManager.h"

#define TCP_MAX_MSG_SIZE 512
#define STR_END_MSG "[/TCP]"

class ofxTCPClient{


	public:
	
		ofxTCPClient();
		~ofxTCPClient();
		void setVerbose(bool _verbose);
		bool setup(string ip, int _port, bool blocking = false);		
		bool close();
		
		//send data as a string - a short message 
		//is added to the end of the string which is 
		//used to indicate the end of the message to 
		//the receiver see: STR_END_MSG (ofxTCPClient.h)
		bool send(string message);
		
		//the received message length in bytes
		int getNumReceivedBytes();

		//send and receive raw bytes lets you send and receive
		//byte (char) arrays without modifiying or appending the data.
		//Strings terminate on null bytes so this is the better option
		//if you are trying to send something other than just ascii strings		
		bool sendRawBytes(const char * rawBytes, const int numBytes);
		
		
		//get the message as a string
		//this will only work with messages coming via
		//send() and sendToAll()
		//or from messages terminating with the STR_END_MSG 
		//which by default is  [/TCP]
		//eg: if you want to send "Hello World" from other
		//software and want to receive it as a string
		//sender should send "Hello World[/TCP]" 
		string receive();
				
		//pass in buffer to be filled - make sure the buffer
		//is at least as big as numBytes
		int receiveRawBytes(char * receiveBytes, int numBytes);	

		
		bool isConnected();
		int getPort();
		string getIP();		
		
		//don't use this one
		//for server to use internally only!
		//--------------------------
		bool setup(int _index, bool blocking = false);
		
		
		
		ofxTCPManager	TCPClient;
		char			tmpBuff[TCP_MAX_MSG_SIZE];
		string			str, tmpStr, ipAddr;
		int				index, messageSize, port;
		bool			connected, verbose;
	
};

#endif	



