move code for creating an event socket to a function