Detect hostname for websocekt connection

Automatically detecting hostname when creating websocket connection rather than hard coding to localhost