Is websocket single threaded?

537 views
Skip to first unread message

z you

unread,
Jul 23, 2022, 2:41:46 PM7/23/22
to WebSocket++
sleep onOpen or onMessage, Unable to accept connections and process messages for other connections
void OnMessage(WebsocketServer *server, websocketpp::connection_hdl hdl, message_ptr msg)  {
  string strMsg = msg->get_payload();
  string strRespon = "receive: " + strMsg;
  std::this_thread::sleep_for(std::chrono::milliseconds(10000));
}

Jacob Burckhardt

unread,
Jul 25, 2022, 6:25:33 PM7/25/22
to z you, WebSocket++
WebSocket++ supports multi-threaded applications but you have to create the threads yourself.  WebSocket++  does not create the threads for you as explained by the documentation:
In order to process user input while network processing occurs in the background we are going to use a separate thread for the WebSocket++ processing loop. This leaves the main thread free to process foreground user input.
Your test example sleeps, but your real program would probably replace sleep with code that does useful work using CPU time.  You probably want that work to be done in another thread if it takes a significant amount of time.  You could make ​OnMessage put the message in a queue and another thread could pop from that queue and spend as much time as it needs processing the message while the WebSocket++ thread still accepts connections and processes messages for other connections.


From: webso...@googlegroups.com <webso...@googlegroups.com> on behalf of z you <zyy455...@gmail.com>
Sent: Saturday, July 23, 2022 7:41 AM
To: WebSocket++ <webso...@googlegroups.com>
Subject: Is websocket single threaded?
 
--
You received this message because you are subscribed to the Google Groups "WebSocket++" group.
To unsubscribe from this group and stop receiving emails from it, send an email to websocketpp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/websocketpp/4db43684-42db-49e0-9805-ad9f406f72cfn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages