Revert "Simplified socket initialization and release"

This reverts commit ec9dff3d631da6049c11781843a8a0bfc204de68.
Fixes compile error