javascript - Return variable by socket client -


i have following question. how can return new value sockets, js file?

app.js

io.on('connection', function (socket) {     socket.currentroomid = 0;     socket.currentroomname = "loading...";     socket.currentroomowner = 1;     socket.currentroomentry = 1.1; }); 

roommanager.js

adapter.query(sql, function(err, rows) {     rows.foreach( (row) => {         socket.currentroomid = parseint(row.id);        socket.currentroomname = row.room_name;        socket.currentroomowner = row.room_owner;        socket.currentroomentry = row.room_entry;     }); }); 

greetings.

you have emit , listen this,

roommanager.js

adapter.query(sql, function(err, rows) {     rows.foreach( (row) => {         // emit setcurrentdata row data        socket.emit('setcurrentdata', { data: row });     }); }); 

app.js

io.on('connection', function (socket) {     socket.currentroomid = 0;     socket.currentroomname = "loading...";     socket.currentroomowner = 1;     socket.currentroomentry = 1.1;      // listen setcurrentdata      socket.on('setcurrentdata', function (row) {        socket.currentroomid = parseint(row.data.id);        socket.currentroomname = row.data.room_name;        socket.currentroomowner = row.data.room_owner;        socket.currentroomentry = row.data.room_entry;     }); }); 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -