मैं अपने टर्ननाडो सर्वर के साथ डब्ल्यूएस कनेक्शन बनाने की कोशिश कर रहा हूं। सर्वर कोड सरल है:वेबसॉकेट: वेबसॉकेट हैंडशेक के दौरान त्रुटि: गैर-खाली 'सेक-वेबसेट-प्रोटोकॉल' हेडर भेजा गया लेकिन कोई प्रतिक्रिया प्राप्त नहीं हुई
class WebSocketHandler(tornado.websocket.WebSocketHandler):
def open(self):
print("WebSocket opened")
def on_message(self, message):
self.write_message(u"You said: " + message)
def on_close(self):
print("WebSocket closed")
def main():
settings = {
"static_path": os.path.join(os.path.dirname(__file__), "static")
}
app = tornado.web.Application([
(r'/ws', WebSocketHandler),
(r"/()$", tornado.web.StaticFileHandler, {'path':'static/index.html'}),
], **settings)
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
मैं here से ग्राहक कोड चिपकाया कॉपी:
$(document).ready(function() {
if ("WebSocket" in window) {
console.log('WebSocket is supported by your browser.');
var serviceUrl = 'ws://localhost:8888/ws';
var protocol = 'Chat-1.0';
var socket = new WebSocket(serviceUrl, protocol);
socket.onopen = function() {
console.log('Connection Established!');
};
socket.onclose = function() {
console.log('Connection Closed!');
};
socket.onerror = function (error) {
console.log('Error Occured: ' + error);
};
socket.onmessage = function (e) {
if (typeof e.data === "string") {
console.log('String message received: ' + e.data);
}
else if (e.data instanceof ArrayBuffer) {
console.log('ArrayBuffer received: ' + e.data);
}
else if (e.data instanceof Blob) {
console.log('Blob received: ' + e.data);
}
};
socket.send("Hello WebSocket!");
socket.close();
}
});
यह मैं ब्राउज़र के कंसोल पर निम्न आउटपुट प्राप्त कनेक्ट करने के लिए प्रयास करता है:
WebSocket connection to 'ws://localhost:8888/ws' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received
वह क्यों है?
अपने क्लाइंट कनेक्शन कोड पोस्ट करें, या हम अनुमान लगाएंगे ... – Myst
मैंने 'चैट -1' प्रोटोकॉल का उपयोग किया। आखिर में मैंने उस भाग को हटा दिया, और प्रोटोकॉल निर्दिष्ट किए बिना डब्ल्यूएस खोला और इस तरह से काम करता है। मुझे अभी भी दिलचस्पी है कि इसे स्वीकार करने के लिए मुझे सर्वर पक्ष को कैसे कॉन्फ़िगर करना चाहिए। – Midiparse