LabVIEW-WebSockets-API icon indicating copy to clipboard operation
LabVIEW-WebSockets-API copied to clipboard

Add closing codes and reasons

Open Cyberfly100 opened this issue 6 years ago • 3 comments

The webocket protocol states that a reason can be given by the endpoint, when sending a closing frame. It should be a two byte code (1000 for "everything is fine") followed by an optional utf-8 encoded message. Python's websockets server generates an error, when no code is sent, assuming something went wrong. It would be good to send a confirmation that closing was expected. I could fix my issue by changing the "close frame.vi" as follows: image Download (valid until 2020-01-31)

I would recommend to make the Ring Menu into a Control and use it as an optional input. Then one can program a client that automatically closes the connection with the correct error code, when e.g. a binary payload instead of an expected text payload is received.

Cyberfly100 avatar Dec 02 '19 13:12 Cyberfly100

Hi Lucas,

The WebSockets specification states:

The Close frame MAY contain a body (the "Application data" portion of the frame) that indicates a reason for closing

The closing body and status code is not required by the WebSockets specification so if the Python library is returning an error then that is an issue with the Python library.

samsharp99 avatar Dec 02 '19 13:12 samsharp99

True. I also wrote that a reason CAN be given. Not sure how well it is handled on the python side. The error is printed but the server keeps running happily. Maybe it is intended as a strong suggestion... Anyways, I thought it is an easy thing to add and it could have sensibel default values (maybe empty by default, but "OK/end of use" when used in the example client at program stop). And it allows the server to know what went wrong in case something is not OK.

Cyberfly100 avatar Dec 02 '19 13:12 Cyberfly100

Yes, that's OK - I will leave the issue open and have no issue with implementing it at some stage but if the Python side is generating an exception/error then that's not an issue with the LabVIEW library.

samsharp99 avatar Dec 02 '19 13:12 samsharp99