How to use Socket.io with Next.js API Routes

The trick is to plug ‘socket.io’ into the http server only once, so checking every access to the api. Try something like this: ./pages/api/socketio.js import { Server } from ‘socket.io’ const ioHandler = (req, res) => { if (!res.socket.server.io) { console.log(‘*First use, starting socket.io’) const io = new Server(res.socket.server) io.on(‘connection’, socket => { socket.broadcast.emit(‘a user … Read more

Socket.IO subscribe to multiple channels

This is all pretty straightforward with the socket.io rooms feature. Take a look at the documentation on LearnBoost wiki. https://github.com/LearnBoost/socket.io/wiki/Rooms It allows for being connected to multiple rooms over a single socket. I put together a quick test with the following code. Server io.sockets.on(‘connection’, function(client){ client.on(‘subscribe’, function(room) { console.log(‘joining room’, room); client.join(room); }) client.on(‘unsubscribe’, function(room) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)