Added timeout to connect.
Improved example code.