Socket.io socket.emit不';不要使用烧瓶
我尝试用flask作为项目制作简单的聊天应用程序,因此我有了页面Socket.io socket.emit不';不要使用烧瓶,socket.io,flask-socketio,Socket.io,Flask Socketio,我尝试用flask作为项目制作简单的聊天应用程序,因此我有了页面 当用户创建新聊天室时,所有其他用户都会看到聊天室 所以我有这个代码,但是socket.emit对它不起作用 我是说flask应用程序没有收到数据这里是代码 document.addEventListener('DOMContentLoaded',function () { // Connect to websocket var socket = io.connect(location.protocol + '//' + doc
当用户创建新聊天室时,所有其他用户都会看到聊天室
所以我有这个代码,但是socket.emit对它不起作用
我是说flask应用程序没有收到数据这里是代码
document.addEventListener('DOMContentLoaded',function () {
// Connect to websocket
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port+'/channels');
// When connected, configure buttons
socket.on('connect', function () {
document.querySelector("#create").onclick=function (){
const new_channel=document.querySelector("#new_chanell").value;
const channels_list=document.querySelector("#channels");
for (let i=0; i<channels_list.length;i++){
if(channels_list[i].value==new_chanell){
document.querySelector("h1").innerHTML="this channel allready here";
return false;}
}
socket.emit('add_channel', {'channel': new_channel});
document.querySelector("h1").innerHTML="new channel";
return false;
}});
所以我把raise(“he”)放在上面,想知道应用程序是否收到了数据,但没有函数根本不调用why在连接URL上传递
/channels
名称空间。如果要这样做,则必须在服务器上将命名空间添加到所有事件处理程序中:
@socketio.on("add_channel", namespace='/channels')
def add_channel(data):
# ...
@socketio.on("add_channel", namespace='/channels')
def add_channel(data):
# ...