当前位置: 首页 > news >正文

好看的学校网站首页wordpress 轻论坛

好看的学校网站首页,wordpress 轻论坛,怎么做可以访问网站连接加密,有域名怎么建立网站coco2dx c HTTP实现 达到的结果如下面的 iPhone截图 android 日志截图 流程图例如以下 功能主要通过CURL c pthread 实现 我实现的不是多线程断点#xff08;假设要实现能够依据我这个进行加入任务序列#xff0c;可參考 cocos2d-x 中AssetsManager的实现#xff0c;事实上… coco2dx c HTTP实现  达到的结果如下面的 iPhone截图 android 日志截图 流程图例如以下 功能主要通过CURL c pthread 实现 我实现的不是多线程断点假设要实现能够依据我这个进行加入任务序列可參考 cocos2d-x 中AssetsManager的实现事实上我的部分也是參考这个写的 为什么写这个呢 原因就是 AssetsManager是不支持断点续传的 博客地址http://blog.csdn.net/vpingchangxin/article/details/22309067 详细能够去CURL官网或者找资料科普一下 PS:假设是版本号公布最后设置超时时间20秒左右否则下载会占用很多其它下载实现效率等问题 我是为了測试 设置超时时间为2秒 1.先创建一个界面进行控制进行下载、停止、删除、进度 并绑定事件 2.在进行下载中开一个线程进行下载 由于牵涉到UI不开线程UI会卡着阻塞UI线程直到下载完毕以下是事件中的控制 HelloWorldSecene.cpp中的实现 void HelloWorld::menuCallback(CCObject* pSender) {CCMenuItem *item (CCMenuItem *)pSender;switch (item-getTag()) {case 1: // down startCCDirector::sharedDirector()-getScheduler()-scheduleSelector(schedule_selector(HelloWorld::updateUI), this, 0, false); // HttpClient中參考isStop false;this-threadStart();break;case 2: // down stopisStop true;break;case 3:if (isStop) {CCLog(downFilePath:%s,downFilePath.c_str());if (access(downFilePath.c_str(), 0) 0) {remove(downFilePath.c_str());CCMessageBox(删除成功, 温馨提示);}else{CCMessageBox(没有找到文件文件夹, 温馨提示);}}else{CCMessageBox(下载中或没有文件下载, 温馨提示);}break;default:break;} } 3。实现线程类并回调设置 // 启动线程的方法 int HelloWorld::threadStart() {pthread_mutex_init(g_downloadMutex, NULL);int errCode0;pthread_t th_curlDown; // 线程初始化do {pthread_attr_t tAttr;errCodepthread_attr_init(tAttr);CC_BREAK_IF(errCode!0);errCodepthread_attr_setdetachstate(tAttr, PTHREAD_CREATE_DETACHED);if(errCode!0) {pthread_attr_destroy(tAttr);break;}errCodepthread_create(th_curlDown, tAttr, thread_funcation, this);} while (0);return errCode; }// 须要线程来完毕的功能都写在这个函数里 void* HelloWorld::thread_funcation(void *arg) {CCLOG(thread started...);HelloWorld *hw (HelloWorld*)arg;hw-ccc new CurlDown(http://developer.baidu.com/map/static/doc/output/BaiduMap_AndroidSDK_v2.4.0_All.zip,hw-downFilePath);// ccc-mDownloadUrl http://developer.baidu.com/map/static/doc/output/BaiduMap_AndroidSDK_v2.4.0_All.zip;// int leng ccc-getDownloadFileLenth();hw-ccc-setDelegate(hw);hw-ccc-downloadControler();return NULL; }4.实现回调进度、成功、错误里面用到线程锁对数据进度更新UI本来对线程就不熟悉问了群里面的大牛看了不少资料 void HelloWorld::onError(CurlDown::ErrorCode errorCode){CCLog(error);pthread_mutex_lock(g_downloadMutex);updateStr error;pthread_mutex_unlock(g_downloadMutex);CCDirector::sharedDirector()-getScheduler()-unscheduleSelector(schedule_selector(HelloWorld::updateUI), this); } void HelloWorld::onProgress(double percent, void *delegate, string filefullPath){ // 下载进度CCLog(donw progress:%.2f%%,percent);if (isStop) {CurlDown * cd (CurlDown *)delegate;// pthread_mutex_lock(g_downloadMutex);cd-setStopDown();// pthread_mutex_unlock(g_downloadMutex);}pthread_mutex_lock(g_downloadMutex);const char * per CCString::createWithFormat(donw progress:%.2f%%,percent)-getCString();updateStr per;downFilePath filefullPath;pthread_mutex_unlock(g_downloadMutex); } void HelloWorld::onSuccess(string filefullPath){CCLog(success);pthread_mutex_lock(g_downloadMutex);updateStr success;downFilePath filefullPath;pthread_mutex_unlock(g_downloadMutex); }5.CurlDown.h CurlDown.cpp类实现 能够直接抽取出来用于不论什么地方。没有牵涉到cocos2d-x部分cocos2d-x 部分能够删除没关系 1)对类初始化 static pthread_mutex_t g_downloadMutex_1;CurlDown::~CurlDown(){mFileLenth 0; } CurlDown::CurlDown():isStop(false),mDownloadUrl(),timeout(2){ // test timeout 2 seconds. if release timeout 20 secondsmFileLenth 0;mFilePath ;pthread_mutex_init(g_downloadMutex_1, NULL); } CurlDown::CurlDown(string downUrl,string filePath):mFileLenth(0),isStop(false),mDownloadUrl(downUrl),timeout(2),mFilePath(filePath){ // test timeout 2 seconds. if release timeout 20 secondsmDownloadUrl downUrl;pthread_mutex_init(g_downloadMutex_1, NULL); }void CurlDown::setDelegate(CurlDownDelegate * delegate) {mDelegate delegate; } 2控制下载方法 void CurlDown::downloadControler() {CCLog(--1-);mFileLenth getDownloadFileLenth(); // 获取远程文件大小if (mFileLenth 0) {cout download file fail... endl;mDelegate-onError(kNetwork);return;}vectorstring searchPaths CCFileUtils::sharedFileUtils()-getSearchPaths();vectorstring::iterator iter searchPaths.begin();searchPaths.insert(iter, mFilePath);CCFileUtils::sharedFileUtils()-setSearchPaths(searchPaths);CCLog(--2-mFileLenth:%f,mFileLenth);mFileName mDownloadUrl.substr(mDownloadUrl.rfind(/) 1);CCLog(--3-);CCLog(mFileName:%s;,mFileName.c_str()); // mFilePath CCFileUtils::sharedFileUtils()-getWritablePath(); // CCLog(--5-);mFilePath mFilePath mFileName;CCLog(mFilePath:%s,mFilePath.c_str());CCLog(--6-);bool ret false;while (true){ // 循环下载 每30秒进行下载 避免断网情况ret download(); //直接下载 进行阻塞线程CCLog(----stop---%s------,isStop?true:false);if (isStop) { // 假设进行停止 breakCCLog(----stop---------);break;}if (ret ){ //下载完毕break;}sleep(0.5); //每次下载中间间隔0.5秒}if (ret) {CCLog(download ok);mDelegate-onSuccess(mFilePath);} else {CCLog(download fail);mDelegate-onError(kUncompress);} } 3核心下载 #pragma mark 进行下载 bool CurlDown::download() {FILE *fp NULL;if(access(mFilePath.c_str(), 0)0) { // 以二进制形式追加fp fopen(mFilePath.c_str(), ab);} else { // 二进制写fp fopen(mFilePath.c_str(), wb);}if (fp NULL) {// 假设文件初始化失败进行返回return false;}// 读取本地文件下载大小long localFileLenth getLocalFileLength(); //已经下载的大小CCLog(filePath:%s。leng:%ld,mFilePath.c_str() , localFileLenth ); //4397779 //3377875CURL *handle curl_easy_init();std::string packageUrl mDownloadUrl; //下载地址下载文件名称curl_easy_setopt(handle, CURLOPT_URL, packageUrl.c_str()); // http://curl.haxx.se/libcurl/c/fopen.htmlcurl_easy_setopt(handle, CURLOPT_TIMEOUT, timeout);curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, my_write_func); //写文件回调方法curl_easy_setopt(handle, CURLOPT_WRITEDATA, fp); // 写入文件对象curl_easy_setopt(handle, CURLOPT_RESUME_FROM, localFileLenth); // 从本地大小位置进行请求数据// curl_easy_setopt(handle, CURLOPT_RESUME_FROM_LARGE, localFileLenth); // 坑curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);curl_easy_setopt(handle, CURLOPT_PROGRESSFUNCTION, my_progress_func ); //下载进度回调方法curl_easy_setopt(handle, CURLOPT_PROGRESSDATA, this); // 传入本类对象CURLcode res curl_easy_perform(handle);fclose(fp);return res CURLE_OK; }以下大家要问道的就是求源代码^..^源代码已经上传github https://github.com/pingchangxin/BPDownload cesd 下载位置http://download.csdn.net/detail/vpingchangxin/7108649 我就不再这里mac她跑到隔壁 windows在没有运行至win繁琐的头痛的结构 转载于:https://www.cnblogs.com/hrhguanli/p/4573005.html
http://www.yutouwan.com/news/212370/

相关文章:

  • 高校工会网站建设工程建设方案
  • 赢了网站怎么做的北京网站建设+招聘信息
  • wordpress 上传网站吗如何查看网站的空间大小
  • 网站开发范本网站制作公司资质
  • 建网站 绑定域名 网址怎样做网站吸引人
  • 莆田外贸建站关键词优化举例
  • 如何在局域网中做网站镇江发布的最新消息
  • 网站推广开户设置wordpress文章图片不显示
  • icp备案查询站长工具团员电子档案查询系统
  • 易企网络网站建设湖南 网站备案
  • 免费建网站 手机网站图片生成二维码在线制作
  • 商务网站建设平台企业网站建设与推广多少钱
  • 河西做网站的公司网站建设相关的博客有哪些
  • 权威做网站的公司微信扫码登记小程序
  • 汽修网站怎么做冯耀宗seo视频教程
  • 网站维护是不是很难做今天济南刚刚发生的新闻
  • 图片网站收录tradekey外贸平台官网
  • 建设银行北京分行网站邯郸建设局网站资质申报
  • 网站建设新闻中心呼和浩特网站推广公司
  • 免费cms建站系统有哪些学院网站设计模板
  • 福州seo推广优化杭州百度人工优化
  • 工信部网站 备案时间dtcms网站开发教程
  • 做电子商务网站免费的行情网站ifind是
  • 宁波市住房与城乡建设部网站如何零基础做网站
  • 网页设计公司建网站网站设计苏州公司网站建设找哪家
  • 网站建设晋icp备如何做亚马逊备案的网站
  • 腾讯空间个人认证 企业认证 网站认证哪种功能用途最齐全??游戏软件开发流程
  • 山东淄博网站建设微信公众号网站建设费
  • 注册的网站医疗网站咨询源码
  • 舟山建设网站公司微信小程序怎么关闭防沉迷