psygames / UnityWebSocket

:whale: The Best Unity WebSocket Plugin for All Platforms.
MIT License
946 stars 192 forks source link

为什么Error事件需要等很久才抛出来? #32

Closed baizp closed 3 months ago

baizp commented 5 months ago

为什么Error事件需要等很久才抛出来?

alec1o commented 3 months ago

Hello,

The reason for the delay in the error event is related to the connection process. First, the client attempts to connect to the server. If it fails to establish the connection after several tries, an exception is generated. This behavior is inherent to WebSocket, as it needs to ensure that the server is either not responding or not accepting the connection before throwing the exception.

I assume you are referring to the error that occurs before the client successfully connects to the server. For more details, please check the implementation at the following link: Implementation Code


你好,

错误事件延迟发生的原因与连接过程有关。首先,客户端会尝试连接到服务器。如果在多次尝试后仍无法建立连接,则会生成异常。这种行为是 WebSocket 的固有特性,因为它需要确保服务器未响应或不接受连接后才会抛出异常。

我猜测你所指的是在客户端成功连接到服务器之前发生的错误。欲了解更多细节,请查看以下链接中的实现:Implementation Code

psygames commented 3 months ago

正如 @alec1o 所说,在网络消息传输中,不论是建立连接还是发送消息,都需要网络响应消息,如果一个地址能够访问到,但是迟迟没有发送响应消息,就会出现 onError 很久才能收到的情况,一般都是等到网络超时了。