Absolutely agree with ferrency's comments.
1) Your client program fork()s and then both parent and
child use the same socket handle. Do not do that. At best,
you are going to get unpredictable results.
2) Whenever you are dealing with networks, never ever assume
that you will always get what you expect. Add some sort of
timeout logic. You can use either