我想在连接套接字后直接从socketio服务器发送消息 .

我试图在套接字监听器的 .use 中执行此操作,但是如果我直接从 .use 发出,则发出的消息在connect事件之前到达,这会混淆某些客户端 .

enter image description here

const listening = socketio.listen(server, { path: '/whatever'});
listening.use(socket => {
   socket.on('connect', ()=>{console.log('not called');});
   socket.on('connected', ()=>{console.log('not called');});
   socket.emit('hello', {to: 'world'});//sent before the connect event (40 in the frames tab of the socket)
});

socketio.on('connected'...) 不是我想要的任何连接,而不仅仅是这个监听器的连接 .

How can I send a socketio message as soon as a client connects to the socket?