-
You must use delete [] instead of delete to get rid of the allocated memory since you're using new []. Come to think of that, Why not just use the vector since you've already stored all the data?
Code:
unsigned int value = *(reinterpret_cast<unsigned int*>(&fullVVuffer[0]));
Eliminates the copying-
And why one byte at a time? If you know how much it's going to be, why not read X bytes at a time? It may be a little trickier, but it will improve performance. If you don't know the size, read in chunks until you have no more to read.
-
No problem, I'm trying to make my code clear and understandable for everyone.. Maybe it wasn't clear that i was sending an integer.. In a later stadium this bytearray will be filled with more values, that need to be split on the server.. this splitting is another issue, which is an issue that i will try to resolve as well. Do keep in mind that i just want unsigned bytes to be sent from the client.. I'm just trying stuff at the moment to find what fits the most..
The endian issue won't be a problem, and I thank you for the code.. allthough i do not fully understand the while loop.. I'll spend some more time on vectors if someone else has other ideas, they are all welcome..
@ Elysia..
How would it be possible to read multiple bytes? Lets say I want to read the first 4 bytes every time.. How would this be done??
-
I'm not well familiar with sockets, but I assume there's an argument that takes the number of bytes to read?
-
There is ways to specify the buffer size and I didn't feel like writing the code to fill the vector with multiple chars ;).
But you can't always assume you get what you ask for. So you need to process what you are giving by the return value of recv.