You have a lot of stuff in your sending program that is commented out - I assume I can delete it all for clarity?
In your sending program you have this
while (i < n)
and there seems to be no code to update the variable n so the WHILE will never end.
Because you use a single character variable name n I can't be certain because if I try to highlight every instance of the variable name every n in the program gets highlighted. Don't use single character variable names - use meaningful names.
I can't tell from your program which variables hold the data that you want to send.
Also, in your program you are printing data inside the WHILE and at the bottom of the program. Are those all supposed to be data that you want to send? It will be much easier just to send the data in one place.
I won't look at the receiving program until we sort out the sending program.
...R