2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | void client::runAsyncClient() { tcpclient = new AsyncClient(); if(!tcpclient) { DBGmsg("Creating AsyncClient class failed!\r\n"); return; } tcpclient->onDisconnect([](void *obj, AsyncClient * c) { client *cc = (client *)obj; // if (cc->tcpclient) // { // c->free(); // delete c; // cc->tcpclient = NULL; // } DBGmsg("Server Disconnect\r\n"); }, this); tcpclient->onConnect(std::bind([](client * cc , AsyncClient * tcp) { DBGmsg("Server Connected\r\n"); }, this, std::placeholders::_2)); tcpclient->onData([](void *arg, AsyncClient * c, void *data, size_t len) { client *cc = (client *)arg; memcpy(cc->g_buf, data, len); //把随机数种复制过去 cc->tcpbuffer = new AsyncTCPbuffer(c); if(! cc->tcpbuffer) { DBGmsg("creating Network class failed!\r\n"); return; } DBGmsg("Connected\r\n"); cc->zuangtai = CC_STAT_CONNETED; cc->data_call_back(); }, this); tcpclient->onTimeout([](void *arg, AsyncClient * c , uint32_t time) { client *cc = (client *)arg; DBGmsg("Time Out\r\n"); }, this); tcpclient->onError(std::bind([](client * cc , AsyncClient * tcp) { DBGmsg("CCcam server onError\r\n"); // if (cc->tcpbuffer) // { // delete cc->tcpbuffer; // cc->tcpbuffer = NULL; // } // if (cc->tcpclient) // { // cc->tcpclient->free(); // delete cc->tcpclient; // cc->tcpclient = NULL; // } // cc->runAsyncClient();// 重连 cc->cc_disconnect_srv();// 重连 }, this, std::placeholders::_2)); if(!tcpclient->connect(server, CC_port)) { DBGmsg("Connecte Error\r\n"); delete tcpclient; tcpclient = NULL; } } |
|Archiver|手机版|小黑屋|软路由
( 渝ICP备15001194号-1|
渝公网安备 50011602500124号 )
GMT+8, 2025-5-11 21:44 , Processed in 0.247335 second(s), 15 queries , Gzip On, Redis On.
Powered by Discuz! X3.5 Licensed
© 2001-2025 Discuz! Team.