websocket core functionality. Handles tcp chunks, gives callbacks for binary/text messages and encodes messages to be sent back to tcp chunks.