[noPoll] Help / Error during WebSocket handshake: Invalid status line

Félix xcodexif en xif.fr
Sab Sep 27 01:19:12 CEST 2014


Hello,

I have trouble using the noPool library as a websocket listener.
I want, when the client is connected, to close the listening socket for allowing other instances of the program to listen and get a client too.
For this, I'm using nopoll_conn_close(listener) inside the nopoll_ctx_set_on_open callback. I see no objection for this.
But that's not the problem : when I write to the client (using nopoll_conn_send_text (conn, "Test", -1)), the websocket connection is closed
 at client side (latest Chromium) with this error : WebSocket connection to 'ws://localhost:8081/' failed: Error during WebSocket handshake: Invalid status line
Is this a bug or a misuse of noPoll library ?

Here is my code sample :

noPollCtx* wsctx = NULL;
noPollConn* $websocket_conn = NULL;
wsctx = nopoll_ctx_new();
if (wsctx == NULL) {
	std::cerr << "Context creating error" << std::endl;
	return EXIT_FAILURE;
}
noPollConn* listener = nopoll_listener_new(wsctx, "0.0.0.0", $websocket_port);
if (not nopoll_conn_is_ok(listener)) {
	std::cerr << "Listener creating error" << std::endl;
	return EXIT_FAILURE;
}
struct _noPoll_callbacks {
	static nopoll_bool onConnOpen (noPollCtx* wsctx, noPollConn* conn, noPollPtr data) {
	if ($websocket_conn != NULL) return false;
		noPollConn* listener = (noPollConn*)data;
		nopoll_conn_close(listener);
		nopoll_loop_stop(wsctx);
		nopoll_conn_send_text (conn, "Test", -1); // return 4
		$websocket_conn = conn;
		return true;
	}
	static void onMsg (noPollCtx* wsctx, noPollConn* conn, noPollMsg* msg, noPollPtr data){}
};
nopoll_ctx_set_on_open(wsctx, &_noPoll_callbacks::onConnOpen, (noPollPtr)listener);
nopoll_ctx_set_on_msg(wsctx, &_noPoll_callbacks::onMsg, NULL);
nopoll_loop_wait(wsctx, 1500000);
if ($websocket_conn == NULL) {
	std::cerr << "Can't get websocket client..." << std::endl;
	return EXIT_FAILURE;
}

Regards
Félix Faisant



Más información sobre la lista de distribución noPoll