| |

VerySource

 Forgot password?
 Register
Search
View: 787|Reply: 3

Why is there no problem when debugging the breakpoint of my network file transfer program?

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-24 00:20:01
| Show all posts |Read mode
UINT dataLength;
m_cSocket.Receive (&dataLength, 4);
CFile destFile ("e:\\11.xls", CFile :: modeCreate | CFile :: modeWrite | CFile :: typeBinary);
byte * data = new byte [dataLength];
m_cSocket.Receive (data, dataLength); destFile.Write (data, dataLength);
delete data;
destFile.Close ();
m_cSocket.Close ();
This paragraph is used to accept files and write files, but in the process of breakpoint debugging, m_cSocket.Receive (data, dataLength); You can see that the data of this sentence is correct, the file written is correct, but one The official operation is incorrect. It seems that the correct data is not received. The written documents are garbled. What is going on?
Reply

Use magic Report

0

Threads

36

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-2-9 18:45:01
| Show all posts
m_cSocket.Receive (data, dataLength); destFile.Write (data, dataLength); There is no guarantee that data of dataLength length will be read in one read operation, usually a loop is used to accept the data.
This is determined by the transmission speed of TCP. In the debug mode, single-step execution has enough time for the TCP transport layer to transmit all data.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-10 14:15:01
| Show all posts
Add sleep (100) to your sending thread;
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-1 17:00:01
| Show all posts
On the first floor, please ask. TCP file transfer is generally a blocking call. If m_cSocket.Receive(data, dataLength) cannot receive data with the length of dataLength, and there is no error, will it return?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list