简体   繁体   English

socket.io 引发错误

[英]Throwing errors with socket.io

I've created an Express app (with Angular) that uses socket.io for real-time communication.我创建了一个 Express 应用程序(使用 Angular),它使用 socket.io 进行实时通信。 How can I return an error from the server to the client within the socket.on() function?如何在socket.on() function 中从服务器向客户端返回错误?

Here's my code:这是我的代码:

io.on('connection', (socket: Socket) => {
    socket.on('create game', () => {
        if(condition) {
            // Want to throw error here
        }
    });
});

You could use a built-in event that socket.io already provides called Connect_failed您可以使用 socket.io 已经提供的名为Connect_failed的内置事件

Here you have more information about Error Handling if you need it, hope it helps!如果需要,您可以在此处获得有关错误处理的更多信息,希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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