fix socket errors and add tls test

fix #116 with test `server-event-test.js` and may fix #144. Additionally it improves the tests by adding a new TLS test `tls-test.js`.