Update realtime.py

Fix connection socket error handling