发送消息时套接字传输关闭 Nestjs Angular
[在此输入图像描述][1] 由于数组中有多条推送消息,我的套接字因传输关闭错误而断开连接
当发送第 8 条消息时,用户可以发送 6 或 7 条消息并将其推送到我的数组中,套接字连接断开
[enter image description here][2]
getMessage(): void {
this.chatService.getNewMessage().subscribe((value) => {
this.getNewMessage(value);
});
}
getNewMessage(value: Message): void {
value.idSender = value.userSender.id;
value.idReciever = value.userReceiver.id;
const us = this.users.find(val => {
return val.id === value.userSender.id
});
if (us) {
// there i push the message
us.messageConversation.push(value);
}
}
[1]: https://i.sstatic.net/wlAd5.png
[2]: https://i.sstatic.net/N5tCw.png
[enter image description here][1]
Due to a mutilple push message in an array, my socket disconnects with a transport close error
User can send 6 or 7 messages when the 8th is send and push it into my array the socket connection disconnects
[enter image description here][2]
getMessage(): void {
this.chatService.getNewMessage().subscribe((value) => {
this.getNewMessage(value);
});
}
getNewMessage(value: Message): void {
value.idSender = value.userSender.id;
value.idReciever = value.userReceiver.id;
const us = this.users.find(val => {
return val.id === value.userSender.id
});
if (us) {
// there i push the message
us.messageConversation.push(value);
}
}
[1]: https://i.sstatic.net/wlAd5.png
[2]: https://i.sstatic.net/N5tCw.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚意识到我使用 socket.io 从客户端(Angular)发送到服务器(NestJS)的对象非常大(69912 个字符),
因此,多次发送重对象会导致套接字断开连接,原因是:
传输关闭
。这可能有帮助。
获取 JavaScript 对象的大小(以字节为单位)。
npm i 对象大小
I just realized that the object that I sent from the client(Angular) to the server(NestJS) with socket.io was very big(69912 characters),
So with several sends of a heavy object it leads to the disconnection of the socket with the reason:
transport close
.It might help.
Get size of a JavaScript object in Bytes.
npm i object-sizeof