Closed readysteadygo2006 closed 7 years ago
You dumped a lot of code, but basically you're saying with your implementation
if a server is terminated and then recreated, no attempt will be made to reconnect to the terminated server, as the code never detects that the connection has terminated
However with the test client, I can see the CLOSE notification comes and it attempts to reconnect, successfully if I start the server again. To reproduce, in one terminal window
$ libwebsockets-test-server
and in another
$ libwebsockets-test-client 127.0.0.1 -l
The -l
makes the test client create "longlived" client sessions to make it easier to see if the client is hanging up and reconnecting or reacting to the server going down.
The client will say
[2017/09/22 05:45:25:9942] NOTICE: dumb: connecting
[2017/09/22 05:45:25:9942] NOTICE: lws_client_connect_2: 0x211cb50: address 127.0.0.1
[2017/09/22 05:45:25:9945] NOTICE: mirror: connecting
[2017/09/22 05:45:25:9945] NOTICE: lws_client_connect_2: 0x21dc7f0: address 127.0.0.1
[2017/09/22 05:45:25:9947] NOTICE: lws_client_connect_2: 0x211cb50: address 127.0.0.1
[2017/09/22 05:45:25:9947] NOTICE: lws_client_connect_2: 0x21dc7f0: address 127.0.0.1
[2017/09/22 05:45:25:9956] NOTICE: checking client ext permessage-deflate
[2017/09/22 05:45:25:9957] NOTICE: instantiating client ext permessage-deflate
[2017/09/22 05:45:25:9957] ERR: Capping pmd rx to 128
[2017/09/22 05:45:25:9957] NOTICE: lws_extension_callback_pm_deflate: option set: idx 1, (null), len 0
[2017/09/22 05:45:25:9957] NOTICE: mirror: LWS_CALLBACK_CLIENT_ESTABLISHED
and then stay like that, until you ^C the server
[2017/09/22 05:45:29:6755] NOTICE: dumb: LWS_CALLBACK_CLOSED
[2017/09/22 05:45:29:6756] NOTICE: dumb: connecting
[2017/09/22 05:45:29:6756] NOTICE: lws_client_connect_2: 0x211cb50: address 127.0.0.1
[2017/09/22 05:45:29:6758] NOTICE: mirror: LWS_CALLBACK_CLOSED mirror_lifetime=469730
[2017/09/22 05:45:29:6758] NOTICE: lws_client_connect_2: 0x211cb50: address 127.0.0.1
[2017/09/22 05:45:29:6758] NOTICE: Connect failed errno=111
[2017/09/22 05:45:29:6758] ERR: CLIENT_CONNECTION_ERROR: dumb: connect failed
(etc)
First confirm the test server / client act the same on your platform. Then if so, align your code with those until your code also acts the same.
Well, if you find anything I should do something about, let me know and I will reopen.
Hi,
I'm trying to use lws to connect to two clients, I want to have a different callback for each client, so I was using the protocol mechanism to achieve this, however the connectivity achieved is intermittent. Specifically if both servers are available when the code is run, then connections will be made, but if a server is terminated and then recreated, no attempt will be made to reconnect to the terminated server, as the code never detects that the connection has terminated.
I have two attempts, the original using lws_client_connect, but then tried lws_client_connect_via_info as lws_client_connect is depreciated. Both give the same result, can you help!
First(lws_client_connect): void lws_mobile_thread(void in) { uint32_t target = ((uint32_t)in); char* targetAddress; uint32_t targetPort;
}
second attempt (lws_client_connect_via_info):
void lws_mobile_thread(void in) { uint32_t target = ((uint32_t)in); char* targetAddress; uint32_t targetPort; unsigned int rl_dumb = 0, rl_mirror = 0, do_ws = 1, pp_secs = 0, do_multi = 0;
}
The common callback and protocol definitions are shown attached below:
static int callback_mobile( struct lws wsi, enum lws_callback_reasons reason, void user, void in, size_t len ) { int n; string output; int maxCount = 0; char outputCStr; int outputLen; string *cmdString;
}
static int callback_server( struct lws wsi, enum lws_callback_reasons reason, void user, void in, size_t len ) { int n; string output; int maxCount = 0; char outputCStr; int outputLen; string *cmdString;
}
enum protocols { PROTOCOL_SERVER = 0, PROTOCOL_MOBILE = 1, PROTOCOL_COUNT };
static struct lws_protocols protocols[] = { { "server-protocol", callback_server, 0, MAX_ECHO_PAYLOAD, }, { "mobile-protocol", callback_mobile, 0, MAX_ECHO_PAYLOAD, }, { NULL, NULL, 0, 0 } / terminator / };