adds tcp socket
refactor some duplicate code to abstract socket class