Nine times out of ten these problems are due to lack of coordination between client writes and server reads and vice versa. For instance, because of streams blocking, your program will lock up if it tries to read when nothing has been written nor will be.
I suggest you go through your code with a fine toothed comb for this sort of problem