Я пишу в веб-приложении, где я хочу отправить JSON-код с клиентской стороны на серверную через Tornado WebSockets с SSL. Когда я хочу установить соединение, Google Chrome показывает в журнале консоли ошибку:
Uncaught InvalidStateError: Failed to execute 'send' on 'WebSocket': Still in CONNECTING State.
Мой сервер Python выглядит так:
from tornado import websocket, web, ioloop
import json
from sqlite3functions import *
class SocketHandler(websocket.WebSocketHandler):
def on_message(self, message):
handleRequest(self, json.loads(message), True)
print(message)
def handleRequest(obj, message, isWebsock):
...
def writeResponse(obj, message, isWebsock):
if (isWebsock):
obj.write_message(message)
else:
print(message)
obj.write(message)
print('msg sent')
app = web.Application([
(r'/w', SocketHandler)
])
if __name__ == "__main__":
app.listen(8888)
ioloop.IOLoop.instance().start()
Мой клиент:
var ws;
function connect() {
ws = new WebSocket('wss://127.0.0.1:8888/w');
ws.onopen = function()
{
ws.send("Message to send");
};
}
$(document).ready(function() {
connect();
$("#Button").on('click', function() {
...
ws.send(data);
});
});
Спасибо