beast: async_read: Transport endpoint is not connected

Hi,

When running the websocket_echo example, I get the following output when connecting to it with a simple program that connects to the server, sends a message and receive the message and then closes the link:

[#1 127.0.0.1:59662] async_read: Transport endpoint is not connected

Sample:

beast::websocket::stream<boost::asio::ip::tcp::socket&> ws {sock};
ws.handshake("127.0.0.1", "/");
ws.write(boost::asio::buffer(std::string("Hello, World!")));

// Receive the message
beast::streambuf sb;
beast::websocket::opcode op;
ws.read(op, sb);

std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "Resp: " << beast::to_string(sb.data()) << std::endl;

ws.close(beast::websocket::close_code::normal);

When closing the link I expected no output because of the following lines (examples/websocket_async_echo_server.hpp:318):

if(ec == beast::websocket::error::closed)
  return;

I’m not sure if this is a bug or a misunderstanding on my side. Let me know.

Regards, Matthijs

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Notionally, the other side may have sent you all kinds of stuff before it received the shutdown instructions. So if you want to do a normal close, you have to read all of it. The same is true for TCP. (Of course, precisely what happens when you don’t do exactly this varies.)

@matthijs So you close the TCP connection without properly closing the websocket connection or giving the server a chance to properly close it?