copy from http://net.go.googlecode.com/hg/websocket/