Replace print statements with proper logging

Fix legacy socket select. Add timeout.