zaphoyd / websocketpp

C++ websocket client/server library
http://www.zaphoyd.com/websocketpp
Other
7.03k stars 1.97k forks source link

Problem with handling websocket server failure #576

Open b62303411 opened 8 years ago

b62303411 commented 8 years ago

What is the proper way to hanlde websocket server instance failure upon start
try websocketServer->listen("127.0.0.1", websocketServerPort); // WILL THROW AN EXCEPTION IF THE PORT IS NOT AVAILABLE // Start the server accept loop websocketServer->start_perpetual(); websocketServer->start_accept(); catch() ( underlying transport error) .. what to do.. ??

do i need to delete my end point ?, if the port is somehow hold by my previous instance that has not closed properly is there any way out of it ? logging an error doesnt help me leading the app to eventualy recover from an error that could be only temporary and rebooting my app every time the server part of it fail seems very bad practice.

zaphoyd commented 8 years ago

Deleting the endpoint, creating a new one, and trying a different port is probably the safest. Its possible that simply calling listen again on the same endpoint with a different port will work. There is also an overload of listen that takes an error code output parameter if you find checking an error code simpler to handle than an exception.