fix socket bug and add unittest