You have to put the bytes at port check inside the while loop (now it is run once immediately after the send and will report a 0 so it does not help to check if that 0 ever changes...), and then you check. Terminate the while loop when the bytes at port number gets equal or above the number of bytes you expect.
