My sio = require('socket.io').listen(app)
is in my server.js file, but I'm calling a method in a library that would like to push a message to the client... say api.user.pushToClient()
How am I able to access sio.sockets
from there? Perhaps my structure is incorrect?
Folder structure:
server.js
api
|--user.js
|--another.js
listen(port); // Create a Socket.IO instance, passing it our server var socket = io. listen(server); // Add a connect listener socket. on('connection', function(client){ console. log('Connection to client established'); // Success!
The short answer is yes.
The socketio. Server() class creates a server compatible with the Python standard library.
Both WebSocket vs Socket.io are popular choices in the market; let us discuss some of the major Difference Between WebSocket vs Socket.io: It provides the Connection over TCP, while Socket.io is a library to abstract the WebSocket connections. WebSocket doesn't have fallback options, while Socket.io supports fallback.
in server.js
append this line
module.exports.sio = sio;
in api/user.js
sio = require('../server').sio;
sio.sockets.on ...
Or did I misunderstand the question?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With