Fixed packet stream errror

-Fixed packet stream error
-Added lock to disconnect