How to send an outside message through open websocket?

Greetings. New to Autobahn Python. I posted a question on Stack Exchange but I can reduce it down further:
How can I send a message through the websocket from outside the factory protocol? Here is my code:

from autobahn.twisted.websocket import WebSocketServerProtocol, \
from twisted.internet import reactor

class MyServerProtocol(WebSocketServerProtocol):

    def onConnect(self, request):
        print("Client connecting: {0}".format(request.peer))

    def onOpen(self):
        print("WebSocket connection open.")

    def onMessage(self, payload, isBinary):
        if isBinary:
            print("Binary message received: {0} bytes".format(len(payload)))
            print("Text message received: {0}".format(payload.decode('utf8')))

        # echo back message verbatim
        self.sendMessage(payload, isBinary)

    def onClose(self, wasClean, code, reason):
        print("WebSocket connection closed: {0}".format(reason))

def send_hypothesis():
    MyServerProtocol().sendMessage(u"this is a message".encode('utf8'))

if __name__ == '__main__':

    factory = WebSocketServerFactory("ws://")
    factory.protocol = MyServerProtocol

    reactor.listenTCP(9001, factory)

You can see that I am trying to send a message from outside the main program callback through the websocket using MyServerProtocol().sendMessage(u"this is a message".encode('utf8')) but I am getting the following error:

if self.state != WebSocketProtocol.STATE_OPEN: builtins.AttributeError: ‘MyServerProtocol’ object has no attribute ‘state’

Surely there is a simple way to send messages through the websocket from outside the main program loop? Any help is appreciated.

Based on the answers here, it seems that my efforts to call MyServerProtocol().sendMessage(u"this is a message2".encode('utf8')) from main were in fact creating a new and unrelated instance of MyServerProtocol rather than piping messages into the existing connection. I was able to send new messages into the open websocket connection using the method described here. Sending a message from the server to the client seems like a very basic operation for a websocket library so I wish that some of Autobahn’s documentation would go into greater depth on this and also to provide some examples of this as most all of the examples, while very helpful in getting started, are limited to echo servers.