Your code is somewhat confusing. You do not need to send characters 1 at a time. The main loop should run 20 times, and each time round it can send 20 characters. And the length of your send and receive data should not be
sizeof(char)
(which is 8) but the count of bytes in the data, which in this case is 1. Also you are trying to print a single character but referring to it as a string. The correct format control for a single character is
%c
. And unless you know that the 20 characters comprise a null terminate sequence you should never use
%s
.
Take a look at
send(2): send message on socket - Linux man page[
^] for more details.