Wrapped up all socket calls so that realtime functionality can easily be disabled

In addition, requests will function better if sockets drop out due to connection limits.

Cleaned up a bit, moved all frontend globals into env include