Open pxjl opened 2 years ago
It's because at each loop of your client, you both send and receive 1024 bytes. However, each time the server receives a 1024 bytes of message, it would echo a 2048 bytes one. Therefore, it takes two loops on the client side to receive one echo, but you called scanf and send in every loop, not every other loop. The asymmetry accounts for the problem. You can solve it by not reading/sending the whole buffer but only strlen(buffer)+1 instead (it only works for string though).
对, 改成2048后就是那边两个循环顶这边一个循环, 你可以改成10240, 可以明显看到那边10个循环顶这1个, 可能不太懂, 我觉得他俩得一样
server的
char buf[1024]
改成char buf[2048]
后server返回的消息会间隔一次,求教这是为什么server.cpp
client.cpp