|
- while (true)
- {
- CSocket sockSrvr;
- int createSucceed=sockSrvr.Create(pDlg->m_iPort);
- if(createSucceed==0)
- {
- continue;
- }
- int listenSucceed=sockSrvr.Listen(); //开始监听
- if(listenSucceed==0)
- {
- continue;
- }
- CSocket recSo;
- SOCKADDR_IN client;
- int iAddrSize=sizeof(client);
- int acceptSucceed=sockSrvr.Accept(recSo,(SOCKADDR *)&client,&iAddrSize); //接受连接并取得对方IP
- if(acceptSucceed==0)
- {
- recSo.Close();
- continue;
- }
- sockSrvr.Close();
- char flag[FLAG]={0};
- if(recSo.Receive(flag,FLAG)!=2)
- {
- recSo.Close();
- continue;
- }
- CString fname;
- FILEINFO myFileInfo;
- recSo.Receive(&myFileInfo,sizeof(FILEINFO));
- int fileLength=myFileInfo.fileLength;
- CString strfileIp,strfileName,strfileLength;
- strfileIp.Format(L"%s",inet_ntoa(client.sin_addr));
- strfileName=myFileInfo.fileName;
- char buf[SIZEFILE]={0};
- CFile f(strfileName,CFile::modeCreate|CFile::modeWrite); //存文件
- int n=0; //接受的字节数 0表示结束
- int temp=0;
- [color=#FF0000]for(;;)
- {
- n=recSo.Receive(buf,SIZEFILE); //接受
- if(n==0) //0表示结束
- {
- recSo.Close();
- break; //接受完毕
- }
- f.Write(buf,n);
- }[/color] f.Close();
- /*******************************************************/
- }
复制代码
问题好像处在红色部分 |
|