Factor out repeated code.
Factor out repeated code.

aaugustin/websockets,andrewyoung1991/websockets,aaugustin/websockets,biddyweb/websockets,aaugustin/websockets,aaugustin/websockets,dommert/pywebsockets