防火墻端口已開啟,是云服務器。在服務器本地能鏈接,在外網(wǎng)不能連上
已攔截跨源請求:同源策略禁止讀取位于 http://xxx:2120/socket.io/?EIO=3&transport=polling&t=N5DPYdR 的遠程資源。(原因:CORS 請求未能成功)。
2120端口已開啟。本地后臺能接收到
前端代碼
$(document).ready(function () {
// 連接服務端
var socket = io('http://xxx:2120');
// 連接后登錄
socket.on('connect', function(){
alert(1);
socket.emit('login', uid);
});
// 后端推送來消息時
socket.on('new_msg', function(msg){
//$(".test").html(msg);
$('#content').html('收到消息:'+msg);
$('.notification.sticky').notify();
});
});