move socket connection to the connect method of API