Changed way of socket reading 

This two commits fix server stalling issue