<code>#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <iostream>
#include <string>
#include <thread>
using tcp = boost::asio::ip::tcp;
int main(){
auto const address = boost::asio::ip::make_address("127.0.0.1");
auto const port = static_cast<unsigned short>(std::atoi("8083"));
boost::asio::io_context ioc{1};
tcp::acceptor acceptor{ioc,{address,port}};
while(1){
tcp::socket socket{ioc};
acceptor.accept(socket);
std::cout<<"socket accepted"<<std::endl;
std::thread{[q = std::move(socket)]() mutable {
boost::beast::websocket::stream<tcp::socket> ws {std::move(q)};
ws.accept();
while(1){
boost::beast::flat_buffer buffer;
ws.read(buffer);
auto out = boost::beast::buffers_to_string(buffer.cdata());
std::cout<<out<<std::endl;
}
}}.detach();
}
return 0;
}
</code>
<code>#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <iostream>
#include <string>
#include <thread>
using tcp = boost::asio::ip::tcp;
int main(){
auto const address = boost::asio::ip::make_address("127.0.0.1");
auto const port = static_cast<unsigned short>(std::atoi("8083"));
boost::asio::io_context ioc{1};
tcp::acceptor acceptor{ioc,{address,port}};
while(1){
tcp::socket socket{ioc};
acceptor.accept(socket);
std::cout<<"socket accepted"<<std::endl;
std::thread{[q = std::move(socket)]() mutable {
boost::beast::websocket::stream<tcp::socket> ws {std::move(q)};
ws.accept();
while(1){
boost::beast::flat_buffer buffer;
ws.read(buffer);
auto out = boost::beast::buffers_to_string(buffer.cdata());
std::cout<<out<<std::endl;
}
}}.detach();
}
return 0;
}
</code>
#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <iostream>
#include <string>
#include <thread>
using tcp = boost::asio::ip::tcp;
int main(){
auto const address = boost::asio::ip::make_address("127.0.0.1");
auto const port = static_cast<unsigned short>(std::atoi("8083"));
boost::asio::io_context ioc{1};
tcp::acceptor acceptor{ioc,{address,port}};
while(1){
tcp::socket socket{ioc};
acceptor.accept(socket);
std::cout<<"socket accepted"<<std::endl;
std::thread{[q = std::move(socket)]() mutable {
boost::beast::websocket::stream<tcp::socket> ws {std::move(q)};
ws.accept();
while(1){
boost::beast::flat_buffer buffer;
ws.read(buffer);
auto out = boost::beast::buffers_to_string(buffer.cdata());
std::cout<<out<<std::endl;
}
}}.detach();
}
return 0;
}
this is my code, and it is giving me this error => The WebSocket handshake Connection field is missing the upgrade token
please help me to resolve it.
I read some article where someone said you can try after changing your browser but still facing the same issue.
New contributor
moksh_mangal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.