Hello everyone,
can somebody explain how recv() function really works? As I understand now it waits for data to be in buffer in TCP level and takes the maximum amount of the third argument of it. But then the problem arises - i use the same function two times in different programs (server and client) in from first look the same ways, but in server it returns the amount expected, while in client it is always 31 bytes no matter what 3rd argument is. And, consequently, the data is not received fully. What could be the cause of it? Or what I don't understand about this function? Thank You.
EDIT: the server side function does not return expected value too...
You probably have an error in your code, so it would be best to show how you invoke recv.
Are you aware that you usually will have to call recv repeatedly to receive all data?
That does not explain why in the other program with almost identical call the retval is always 128.
And i don't really understand why i should not receive everything if i do not store that data, but simply output in the screen? (That writeout simply couts a string and does some fancy tricks not related to receiving)
And if recv takes data in portions then why doesn't it take the rest of data? (Although i assume recv takes the exact data sent by send() function)
And if recv takes data in portions then why doesn't it take the rest of data? (Although i assume recv takes the exact data sent by send() function)
That could be because the data has not been received yet. recv will give you the data in arbitrary portions and your program needs to handle that correctly.
Perhaps you're sending the data in portions of 32 and 128 bytes? Either way, all data you're sending will be received on the other end - just not necessarily in the same number of fragments.
You actually were right! Thank you very much! Now when it's so obvious it's a surprise how i didn't thought of that... :D i had set wrong amount of data to send, because i used sizeof instead of static constant.