machinezone / IXWebSocket

websocket and http client and server library, with TLS support and very few dependencies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

qknight opened this issue · comments

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, "");
}

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

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.

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

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