本文整理汇总了C++中TcpSocket::tcpRecv方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::tcpRecv方法的具体用法?C++ TcpSocket::tcpRecv怎么用?C++ TcpSocket::tcpRecv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::tcpRecv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processReprogramme
int processReprogramme(TcpSocket &r_tcp, Hdev h_dev){
Hserial h_serial;
FILE* r_file;
Hfile h_file(FILENAME,"w");
if (r_tcp.tcpAccept() == 1){//tcp accept成功
char recv_buf[2500];
int recv_len = r_tcp.tcpRecv(recv_buf,10);
int result = r_tcp.check(recv_buf, 10, RCONN, 4);
if (result == 1){// check true
h_file.setSize(recv_buf);
int file_size = h_file.getSize();
int buf_len = 0;
int wait_count =0;
while(buf_len<file_size){//while receive data
recv_len = r_tcp.tcpRecv(recv_buf,2500);
if (recv_len>0){//received data, store into file
buf_len = buf_len+recv_len;
h_file.writeFile(recv_buf, recv_len);
} else{//can not receive data more than 5 times, close socket
if (wait_count>5){
cout<<"socket error, already received "<<buf_len<<endl;
h_file.refresh();
return 1;
}
wait_count = wait_count+1;
}
}
h_file.closeFile();
cout<<"file closed"<<endl;
if (file_size>0 && buf_len==file_size){
h_dev.startBSL();
result = program(h_serial);
h_dev.resetNode();
return result;
} else{
return 1;
}
} else{//check false
return 1;
}
}
return 1;
}