#ifndef _OF_TCP_CLIENT_
#define _OF_TCP_CLIENT_

#include "ofConstants.h"
#include "ofThread.h"
#include "ofTCPManager.h"

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

class ofTCPClient : public ofThread{





	public:
	
		ofTCPClient();
		~ofTCPClient();
		void setVerbose(bool _verbose);
		bool setup(string ip, int _port);		
		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 (ofTCPClient.h)
		bool send(string message);
		
		//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();
		
		//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);
		
		//gives you a ptr to the received buffer
		//use getNumReceivedBytes to find the buffer size
		char * receiveRawBytes();
		
		//pass in buffer to be filled - make sure the buffer
		//is at least as big as TCP_MAX_MSG_SIZE (ofTCPClient.h)
		//returns the received buffer length
		int receiveRawBytes(char * receiveBytes);		
		
		bool isConnected();
		int getPort();
		string getIP();		
		
		//don't use this one
		//for server to use internally only!
		//--------------------------
		bool setup(int _index);
		
		//don't call this
		void threadedFunction();
		
		ofTCPManager	TCPClient;
		char			tmpBuff[TCP_MAX_MSG_SIZE];
		char			safeBuff[TCP_MAX_MSG_SIZE];
		string			str, tmpStr, ipAddr;
		int				index, messageSize, port;
		bool			connected, verbose;
	
};

#endif	



