Add code to manage socket