I finally got a chance to sit down with PA3 again today. Thankfully, the code I wrote at the airport last weekend compiled and ran. However, it didn't work. The server wasn't receiving the same data that was being sent...or so it appeared.
The problem had two parts -- first, memcpy doesn't work exactly the same way as sprintf. Getting the data into the sending buffer was a whole lot easier when I switched to sprintf to write the integers into the character array. Second, the server appeared to be receiving garbage. The problem was the buffer length used in the recv call. I was receiving the entire length of the buffer rather than just the number of bytes expected. Once I made that change, the data came through nice and clean.
Then, miraculously, everything else fell into place pretty neatly. The only other problem is that I was looping through the sorted list backwards and printing the numbers in the wrong order.
So now, the only reason that I say it's almost done is because of the error checking. There is a lot of validation that I'm just skipping at the moment. The code is riddled with "TODO" comments marking where additional validation needs to be performed. I may or may not have a chance to get back in and do those things, so it's possible that the version that I just checked in is the final form of this assignment.
No comments:
Post a Comment