added tcp reconnect. code refactoring needed.