A simple class to do line-based TCP communication. To be used with the NetServicesMin library-.
Diff: tcplinestream.h
- Revision:
- 0:f2727a16072f
- Child:
- 1:28416a5a4ec5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tcplinestream.h Sat Jan 29 22:42:14 2011 +0000 @@ -0,0 +1,41 @@ +#ifndef __TCPLINESTREAM__H__ +#define __TCPLINESTREAM__H__ + +#include "TCPSocket.h" +#include "string" + +#define BUFSIZE 1024 + +using namespace std; + +class TCPLineStream +{ + public: + TCPLineStream(const char *host, int port, const char* _term="\r\n"); + ~TCPLineStream(){close();}; + bool open(); + void close(); + + string readLine(int strLen=64); + void sendLine(string line); + + private: + void init(); + void onTCPSocketEvent(TCPSocketEvent e); + + const char *_server; + int _port; + + bool _connecting; + bool _connected; + bool _closed; + TCPSocket *_socket; + + char _readbuf[BUFSIZE]; + int _readpos; + int _readlen; + + const char* _term; +}; + +#endif \ No newline at end of file