[Libwebsockets] newbie question: why is my callback never invoked with LWS_CALLBACK_PROTOCOL_INIT ?

Dave Horton daveh at beachdognet.com
Mon Sep 3 18:02:08 CEST 2018


OK, I think I figured out my problem.

I need to give the protocol a name (in protocols[]) in order to get the LWS_CALLBACK_PROTOCOL_INIT callback, even if I dont want to send a sub-protocol in my signaling.

So I changed to this:

static struct lws_protocols protocols[] = {
  {"asapp", ws_callback, 0, 128},		// added name=asap
	{ NULL, NULL, 0, 0 } /* terminator */
};

// added options
static const struct lws_protocol_vhost_options pvo = {
	NULL,		/* "next" pvo linked-list */
	NULL,	/* "child" pvo linked-list */
	"asapp",	/* protocol name we belong to on this vhost */
	""		/* ignored */
};

...

	memset(&info, 0, sizeof info); 
	info.port = CONTEXT_PORT_NO_LISTEN;
	info.protocols = protocols;
  info.pvo = &pvo;	// added this
	info.pt_serv_buf_size = 32 * 1024;


and I get the callback.  


On Sep 3, 2018, at 10:48 AM, Dave Horton <daveh at beachdognet.com> wrote:

I am trying to write a simple websockets client program that reads a wav file into memory, then establishes a ws connection to a server and feeds the audio to that server.

This is my first try with libwebsockets so I expect I am missing the obvious.

I don’t want to supply a sub-protocol in my websocket connection so I am using this:

static struct lws_protocols protocols[] = {
 {NULL, ws_callback, 0, 128},
 { NULL, NULL, 0, 0 } /* terminator */
};


creating my context, and then waiting in my ws_callback for an invocation with reason LWS_CALLBACK_PROTOCOL_INIT, but it never comes.
In the callback I log each time the callback is invoked and the reason, and this is what I see:

$ ./transcribe -f ../prompts/example-question-payment.wav 
[2018/09/03 10:38:41:9809] USER: LWS minimal transcribe function
[2018/09/03 10:38:41:9810] USER:    ./transcribe -f <wav file> server
[2018/09/03 10:38:41:9811] USER: Reading 265600 samples
[2018/09/03 10:38:41:9814] DEBUG: _realloc: size 768: context
[2018/09/03 10:38:41:9814] DEBUG: _realloc: size 32768: pt_serv_buf
[2018/09/03 10:38:41:9814] DEBUG: _realloc: size 38912: fds table
[2018/09/03 10:38:41:9815] DEBUG: _realloc: size 38912: lws_lookup
[2018/09/03 10:38:41:9816] DEBUG: _realloc: size 448: event pipe wsi
[2018/09/03 10:38:41:9816] DEBUG: lws_role_transition: 0x7fbbf8c03170: wsistate 0x200, ops pipe
[2018/09/03 10:38:41:9816] DEBUG: event pipe fd 4
[2018/09/03 10:38:41:9816] DEBUG: __insert_wsi_socket_into_fds: 0x7fbbf8c03170: tsi=0, sock=4, pos-in-fds=0
[2018/09/03 10:38:41:9816] DEBUG: _realloc: size 648: create vhost
[2018/09/03 10:38:41:9820] DEBUG: _realloc: size 112: vhost-specific plugin table
[2018/09/03 10:38:41:9820] DEBUG: _realloc: size 8: same vh list
[2018/09/03 10:38:41:9821] NOTICE: Creating Vhost 'default' (serving disabled), 1 protocols, IPv6 off
[2018/09/03 10:38:41:9960] USER: lws init succeeded, starting service loop
[2018/09/03 10:38:41:9960] USER: ws_callback called, reason: 31
[2018/09/03 10:38:41:9961] USER: ws_callback called, reason: 71


31=LWS_CALLBACK_GET_THREAD_ID
71=LWS_CALLBACK_EVENT_WAIT_CANCELLED

LWS_CALLBACK_PROTOCOL_INIT = 27, but that never comes

My (very short) code can be seen in full here: https://gist.github.com/davehorton/5136b200d8eb3c514698d5300b87aa76

any ideas what I am doing wrong?







More information about the Libwebsockets mailing list