// tcp客户端,增加了心跳报文。 #include "_el.h" using namespace eviwbh; ctcpclient tcpclient; // tcp通讯的客户端。 string strsendbuffer; // 发送报文的buffer。 string strrecvbuffer; // 接收报文的buffer。 bool biz000(const int timeout); // 心跳报文。 bool biz001(const int timeout); // 登录。 bool biz002(const int timeout); // 查询余额。 bool biz003(const int timeout); // 转帐。 int main(int argc,char *argv[]) { if (argc!=4) { printf("Using:./clientHeartbeat ip port timeout\n"); printf("Example:./clientHeartbeat 127.0.0.1 5005 10\n\n"); return -1; } if (tcpclient.connect(argv[1],atoi(argv[2]))==false) { printf ("tcpclient.connect() failed.\n"); return -1; } login(atoi(argv[3])); // 登录。 check_balance(atoi(argv[3])); // 查询余额。 sleep(6); heartbeat(atoi(argv[3])); // 发送心跳报文。 sleep(6); transfer(atoi(argv[3])); // 转帐。 } bool biz000(const int timeout) // 心跳报文。 { strsendbuffer="0"; if (tcpclient.write(strsendbuffer)==false) { printf("tcpclient.write() failed.\n"); return false; } cout << "发送:" << strsendbuffer << endl; if (tcpclient.read(strrecvbuffer,timeout)==false) { printf("tcpclient.read() failed.\n"); return false; } cout << "接收:" << strrecvbuffer << endl; return true; } bool biz001(const int timeout) // 登录。 { strsendbuffer="113922200001123456"; if (tcpclient.write(strsendbuffer)==false) { printf("tcpclient.write() failed.\n"); return false; } cout << "发送:" << strsendbuffer << endl; if (tcpclient.read(strrecvbuffer,timeout)==false) { printf("tcpclient.read() failed.\n"); return false; } cout << "接收:" << strrecvbuffer << endl; return true; } bool biz002(const int timeout) // 查询余额。 { strsendbuffer="26262000000001"; if (tcpclient.write(strsendbuffer)==false) { printf("tcpclient.write() failed.\n"); return false; } cout << "发送:" << strsendbuffer << endl; if (tcpclient.read(strrecvbuffer,timeout)==false) { printf("tcpclient.read() failed.\n"); return false; } cout << "接收:" << strrecvbuffer << endl; return true; } bool biz003(const int timeout) // 转帐。 { strsendbuffer="362620000000016262000000001100.8"; if (tcpclient.write(strsendbuffer)==false) { printf("tcpclient.write() failed.\n"); return false; } cout << "发送:" << strsendbuffer << endl; if (tcpclient.read(strrecvbuffer,timeout)==false) { printf("tcpclient.read() failed.\n"); return false; } cout << "接收:" << strrecvbuffer << endl; return true; }