websocket 消息是否会丢失? [英] Can websocket messages get lost or not?

查看:195
本文介绍了websocket 消息是否会丢失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发 Java WebSocket 客户端应用程序,我必须确保客户端收到来自服务器的每条消息.由于连接中断,我是否可能丢失一些消息(一旦它们从服务器发送)?WebSocket 是基于 TCP 的,所以这不应该发生吧?

I'm currently developing a Java WebSocket Client Application and I have to make sure that every message from the server is received by the client. Is it possible that I lose some messages (once they are sent from the server) due to a connection interruption? WebSocket is based on TCP so this shouldn't happen right?

推荐答案

它可能发生.TCP 保证了数据包的顺序,但这并不意味着即使底层网络发生不可恢复的故障,从服务器发送的所有数据包都会到达客户端.想象一下,当您的应用程序与您的服务器进行通信时,有人在最糟糕的时间拔出您的 LAN 电缆或关闭您的 WiFi 接入点.TCP 没有克服这样的麻烦.

It can happen. TCP guarantees the order of packets, but it does not mean that all packets sent from a server reach a client even when an unrecoverable trouble happens in an underlying network. Imagine someone pulls out your LAN cable or switches off your WiFi access point at the worst timing while your application is communicating with your server. TCP does not overcome such a trouble.

为了确保从您的服务器发送的每条 WebSocket 消息都到达您的客户端,您必须在应用层中实现某种 SYN/ACK.

To ensure that every WebSocket message sent from your server reaches your client, you have to implement some kind of SYN/ACK in the application layer.

这篇关于websocket 消息是否会丢失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆