简体   繁体   中英

SocketIO/NodeJS - Error using socket.emit

I'm using the following code:

 var app = require('http').createServer(); var io = require('socket.io')(app); app.listen(1337); io.on('connection', function (socket) { socket.emit("error", {title: 'Watch your mouth!', msg: 'Please watch your language, or go to the 18+ chat.'}); }); 

and I get the following error:

Error: Uncaught, unspecified "error" event. ([object Object]) Does anyone have any ideas of why this is?

Node.js has special handling for the error event, and will do that if you don't handle it. (to make sure that uncaught errors don't slip between the cracks)

Choose a different event name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM