#include "MyThread2.h"#include "osapi/osapi.h"#include "GBK.h"#include "QMessageBox"MyThread2::MyThread2(QString hello,QObject *parent): QThread(parent){word=hello;}MyThread2::~MyThread2(){wait();}void MyThread2::run(){OS_SockAddr local(GBK::FromUnicode(word).c_str(),9003);OS_UdpSocket sockfile;sockfile.Open(local,true);OS_SockAddr peer;char buf[218];//QMessageBox::information(NULL,"hello",GBK::ToUnicode("你正在接收一个文件!"));if (sockfile.RecvFrom(buf,218,peer)>=0){FILE* file=fopen("hello.txt","wb");while(1){char buf2[218];if (sockfile.RecvFrom(buf2,218,peer)<0){break;}if (strcmp(buf2,"end")==0){//获取当下时间time_t now=time(NULL);tm one=*localtime(&now);int hour=one.tm_hour;int minute=one.tm_min;int second=one.tm_sec;char buftime[1024];if (hour>=0&&hour<=12){sprintf(buftime,"AM-%d-%d-%d: ",hour,minute,second);}else{sprintf(buftime,"PM-%d-%d-%d: ",hour,minute,second);}QString strtime=GBK::ToUnicode(buftime);QString buf3=GBK::ToUnicode("文件接收成功!");emit RecvFile(strtime,buf3);break;}fwrite(buf2,1,218,file);}sockfile.Close();fclose(file);}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。