A simple class to do line-based TCP communication. To be used with the NetServicesMin library-.

Dependents:   pop3demo

Committer:
hlipka
Date:
Sat Jan 29 22:42:14 2011 +0000
Revision:
0:f2727a16072f
Child:
1:28416a5a4ec5
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:f2727a16072f 1 #ifndef __TCPLINESTREAM__H__
hlipka 0:f2727a16072f 2 #define __TCPLINESTREAM__H__
hlipka 0:f2727a16072f 3
hlipka 0:f2727a16072f 4 #include "TCPSocket.h"
hlipka 0:f2727a16072f 5 #include "string"
hlipka 0:f2727a16072f 6
hlipka 0:f2727a16072f 7 #define BUFSIZE 1024
hlipka 0:f2727a16072f 8
hlipka 0:f2727a16072f 9 using namespace std;
hlipka 0:f2727a16072f 10
hlipka 0:f2727a16072f 11 class TCPLineStream
hlipka 0:f2727a16072f 12 {
hlipka 0:f2727a16072f 13 public:
hlipka 0:f2727a16072f 14 TCPLineStream(const char *host, int port, const char* _term="\r\n");
hlipka 0:f2727a16072f 15 ~TCPLineStream(){close();};
hlipka 0:f2727a16072f 16 bool open();
hlipka 0:f2727a16072f 17 void close();
hlipka 0:f2727a16072f 18
hlipka 0:f2727a16072f 19 string readLine(int strLen=64);
hlipka 0:f2727a16072f 20 void sendLine(string line);
hlipka 0:f2727a16072f 21
hlipka 0:f2727a16072f 22 private:
hlipka 0:f2727a16072f 23 void init();
hlipka 0:f2727a16072f 24 void onTCPSocketEvent(TCPSocketEvent e);
hlipka 0:f2727a16072f 25
hlipka 0:f2727a16072f 26 const char *_server;
hlipka 0:f2727a16072f 27 int _port;
hlipka 0:f2727a16072f 28
hlipka 0:f2727a16072f 29 bool _connecting;
hlipka 0:f2727a16072f 30 bool _connected;
hlipka 0:f2727a16072f 31 bool _closed;
hlipka 0:f2727a16072f 32 TCPSocket *_socket;
hlipka 0:f2727a16072f 33
hlipka 0:f2727a16072f 34 char _readbuf[BUFSIZE];
hlipka 0:f2727a16072f 35 int _readpos;
hlipka 0:f2727a16072f 36 int _readlen;
hlipka 0:f2727a16072f 37
hlipka 0:f2727a16072f 38 const char* _term;
hlipka 0:f2727a16072f 39 };
hlipka 0:f2727a16072f 40
hlipka 0:f2727a16072f 41 #endif