Fix echoserver example program to be more useful.

- fixed several bugs and added more error checking in echoserver
- fixed Socket::listen() to return 0 on error.
- put in clean exit logic for echoserver.