[Libwebsockets] [libwebsockets] #47: How to detect and kill and idle client connection on the server and kill it?

Trac trac at libwebsockets.org
Thu Nov 7 17:51:01 CET 2013


#47: How to detect and kill and idle client connection on the server and kill
it?
------------------------------------+-----------------
 Reporter:  jdnevarez               |      Owner:
     Type:  task                    |     Status:  new
 Priority:  major                   |  Milestone:
Component:  libwebsocket test apps  |    Version:
 Keywords:                          |
------------------------------------+-----------------
 I would my server to detect client idle connections and kill them. I tried
 the code below; but all wsi->state is 4 (WSI_STATE_ESTABLISHED) all the
 time. Please advice how to do that.

 void checkIdleClients() {
         int n;
         struct libwebsocket *wsi;
     int count = context->fds_count;


         dolog(LOG_INFO, "START: Total Connected Clients: %d\n", count -
 1);

         for (n = 0; n < count ; n++) {

                 /* make sure a cleint was not discconneted in the middle
 of this loop */
                 if (n >= context->fds_count)
                         break;

                 wsi = context->lws_lookup[context->fds[n].fd];
                 if (wsi && wsi->user_space) {
                         struct per_session_data_tun *pss = (struct
 per_session_data_tun *)wsi->user_space;
                         dolog(LOG_INFO, "STATE: %d ClientId: %s\n",
 wsi->state, pss->id);

                 if (wsi->state == WSI_STATE_DEAD_SOCKET ||
                 wsi->state == WSI_STATE_CLIENT_UNCONNECTED) {
 libwebsocket_close_and_free_session(context, wsi,
 LWS_CALLBACK_CLIENT_CONNECTION_ERROR);
                         }
                 }
         }

         dolog(LOG_INFO, "END: Total Connected Clients: %d\n",
 context->fds_count - 1);

 }

--
Ticket URL: <http://libwebsockets.org/trac/libwebsockets/ticket/47>
libwebsockets <http://libwebsockets.org>
libwebsockets C library



More information about the Libwebsockets mailing list