Building42 / Telegraph

Secure Web Server for iOS, tvOS and macOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to deal with sticky or half a pack when send with data

donly opened this issue · comments

commented

Hi, While sending json data with client.send(data: json), sometimes will cause websocket client disconnection:

[connection] nw_socket_handle_socket_event [C1:1] Socket SO_ERROR [54: Connection reset by peer]
[CLIENT] WebSocket disconnected - error: Broken pipe

As you said that The WebSocket implementation in Telegraph is kinda bare bones in #30 (comment).

Any solutions or suggestions to fix sticky package message pls.

Are you sending large amounts of JSON data? The WebSocket implementation should be fine for small amounts of data, but it isn't optimized for large payloads.

Otherwise this is probably an issue at the network layer. Normally the websocket should not disconnect unless the underlying socket is closed for some reason.

The best way to handle this might be to keep track of what you're sending to the client and if for some reason the client gets disconnected, wait for the client to reconnect and then send the data again after the handshake.