Web sitemde bir sohbet odası yapmak için socket.io
kullanıyorum, bilgisayarımda çalıştırdığımda sorun yok, ancak üretim sunucusunda çalıştırdığımda socket.io.js
çıktı aşağıdakiler hata: sunucu ve web sitesi portu 80
ile nginx
arkasında port 8080
dinlediğiWebSocket handshake 400 yanıt veriyor, ancak hala çalışıyor
istemci için ben [email protected]
kullanıyorum
WebSocket connection to 'ws://myWebsite.com/socket.io/?EIO=3&transport=websocket&sid=1qtzy4QRde6G-PHkAAAU' failed: Error during WebSocket handshake: Unexpected response code: 400
, her şey hata mesajı dışında çalışıyor, ancak sohbet odası hala etkin, bu cok garip.
Ben Yığın taşması bazı benzer sorunlar arandı, ve önerilen çözümler zaten benim nginx
ayarları (/etc/nginx/sites-enabled/myWebsite.com
) şunlardır:
server {
listen 80;
server_name myWebsite.com;
location/{
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
}
}
Meteor WebSocket handshake error 400 with nginx Meteor WebSocket connection to 'ws://.../websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
sohbet odası hala çalışır rağmen, hala
Hata iletisinden kurtulmak istediğinizde, aşağıdaki kod socket.io
ilgili koddur:
// I use angular.js as the front-end framework
function Socket (socketFactory, $rootScope) {
var ioSocket = io.connect(window.location.host);
var socket = socketFactory({ioSocket : ioSocket});
return {
on: function (eventName, callback) {
socket.on(eventName, function() {
var args = arguments;
$rootScope.$apply(function() {
callback.apply(socket, args);
});
});
},
emit: function (eventName, data, callback) {
socket.emit(eventName, data, function() {
var args = arguments;
$rootScope.$apply(function() {
if (callback) {
callback.apply(socket, args);
}
});
});
}
};
}
Socket.$inject = ['socketFactory', '$rootScope'];
angular.module('core').factory('Socket', Socket);
Socket.on('new message', function (data) { ... });
Soket nasıl bağlanır? İkinci istek mi gönderiyor? Websockets'a yükseltiyor mu yoksa xhr'a mı yedekleniyor? –
Bunun nasıl çalıştığını bilmiyorum, iki tarayıcı sekmesi açtım, her ikisi de 400 cevabı aldım, ancak her ikisi de birbirinden mesaj alabilir – kitlee