easywsclient
easywsclient copied to clipboard
Websocket::close() doesn't disconnect correctly
I'm calling Websocket::close() in my destructor, but the it disconnects only if I close my program.
Any progress on this? I'm facing the same problem.
My workaround was to add closesocket(sockfd);
after line 425 in easywsclient.cpp. I don't know if it closes the connection properly but it at least doesn't keep it open forever. I myself have switched to websocketpp, a more complete library which doesn't suffer from this issue.
My workaround was to add
closesocket(sockfd);
after line 425 in easywsclient.cpp. I don't know if it closes the connection properly but it at least doesn't keep it open forever. I myself have switched to websocketpp, a more complete library which doesn't suffer from this issue.
it works. not exact line 425, but at the end of close() function body.
I have noticed this behavior can be seen by running the tests:
- Build the tests with
make test
, start thetestServer.js
withnode
, and launcheasywsclient.t
in a debugger such as GDB. - Place a breakpoint at the end of
main()
to prevent the test application from closing afterRUN_ALL_TESTS()
returns. - Run the the tests.
- Once the breakpoint is hit, note there are several open TCP sockets. For example, on Linux:
$ lsof -p $(pidof easywsclient.t) | grep TCP easywscli 22634 james 3u IPv6 634795 0t0 TCP localhost:36496->localhost:8123 (ESTABLISHED) easywscli 22634 james 4u IPv6 634799 0t0 TCP localhost:36498->localhost:8123 (ESTABLISHED) easywscli 22634 james 5u IPv6 643270 0t0 TCP localhost:36500->localhost:8123 (ESTABLISHED) easywscli 22634 james 6u IPv6 643274 0t0 TCP localhost:36502->localhost:8123 (ESTABLISHED)
I expected the TCP sockets to be closed when the WebSocket
class is destroyed, regardless if WebSocket::close()
has been called. I observed this behavior with commit afc1d8cfc584e0f1f4a77e8c0ce3e979d9fe7ce2.