machinezone / IXWebSocket

websocket and http client and server library, with TLS support and very few dependencies
BSD 3-Clause "New" or "Revised" License
551 stars 177 forks source link

'Normal closure' on stop() string confuses golang.org/x/net/websocket #451

Open qknight opened 1 year ago

qknight commented 1 year ago

Problem

The default implementation of stop() sends this data, which can be seen in wireshark:

0000 03 e8 4e 6f 72 6d 61 6c 20 63 6c 6f 73 75 72 65 ..Normal closure

This confused my go application because it received a message with the contents:

/R"<\n

And it was quite hard to debug. I'm not sure if this is a bug at all. It seems that golang.org/x/net/websocket interpretes the reason as a normal message but instead of the text

'Normal closure' 

I see

'/R"<\n' 

with \n being a newline.

Solution

m_webSocket->stop(ix::WebSocketCloseConstants::kNormalClosureCode, "");

Detailed problem & solution

default stop code confused my application

-- IXWebSocket.h --
// stop is synchronous
void stop(uint16_t code = WebSocketCloseConstants::kNormalClosureCode,
     const std::string& reason = WebSocketCloseConstants::kNormalClosureMessage);

Adaption to the stop call

FilesClient::~FilesClient()
{
    LOGL(<< "Disconnecting websocket", LogLevel_INFO);
    m_webSocket->stop(ix::WebSocketCloseConstants::kNormalClosureCode, "");
}
bsergean commented 1 year ago

ps: have you tried to use the gorilla library, or something more recent? I think that net module is not super supported and legacy.

qknight commented 1 year ago

In pankat I use these libraries:

"github.com/gocraft/web"
"golang.org/x/net/websocket"
"net/http"

Maybe I should have tried a more recent implementation. For me it works right now but on the next iteration I keep this in mind.

I've added this issue in case someone gets down the same rabbit hole.

qknight commented 1 year ago

https://github.com/gorilla development has stalled also.

bsergean commented 1 year ago

I’ve used this one last year -> github.com/gobwas/ws

I remember when the gorilla maintainer said he was stepping down, so yeah it must have stalled.

On Apr 7, 2023, at 2:42 AM, Joachim Schiele @.***> wrote:

https://github.com/gorilla development has stalled also.

— Reply to this email directly, view it on GitHub https://github.com/machinezone/IXWebSocket/issues/451#issuecomment-1500125370, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2O6UOAHUD6ECQT5RGU24TW77OPNANCNFSM6AAAAAAV3TDN5M. You are receiving this because you commented.

qknight commented 1 year ago

https://github.com/gobwas/ws maybe I'll give this a try this week.