'Waits for and deserializes messages.
Returns a single message; the oldest not yet processed. If the client
has already closed the connection, returns None.  This is different
from normal socket behavior because the empty string is a valid
websocket message.'

def wait(self):

    while (not self._msgs):
        if self.websocket_closed:
            return None
        delta = self.socket.recv(8096)
        if (delta == ''):
            return None
        self._buf += delta
        msgs = self._parse_messages()
        self._msgs.extend(msgs)
    return self._msgs.popleft()
