<div dir="ltr">Hello all<div>i want to be able to send back response only to selected connected clients and not as <br>shown in the example using :<br>lws_callback_on_writable_all_protocol.<br></div><div>i searched the mailing list and found this answer :<br><a href="https://libwebsockets.org/pipermail/libwebsockets/2016-January/002177.html">https://libwebsockets.org/pipermail/libwebsockets/2016-January/002177.html</a><br><br></div><div>As suggested i need to keep list of wsi amd user id's </div><div>I just didn't understand why i need to use <span style="color:rgb(0,0,0);white-space:pre-wrap">lws_callback_on_writable() </span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap">As you can see i will invoke function to response to selected users </span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap">In the </span><span style="color:rgb(0,0,0);white-space:pre-wrap">LWS_CALLBACK_SERVER_WRITEABLE case </span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"><br></span></div><div><font color="#000000"><span style="white-space:pre-wrap">Now what i have in my web socket handler/callback  function :</span></font></div><div><font color="#000000"><span style="white-space:pre-wrap">where do i need to use </span></font><span style="color:rgb(0,0,0);white-space:pre-wrap">lws_callback_on_writable() ?</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"><br></span></div><div><font color="#000000"><span style="white-space:pre-wrap">switch (reason) {

        case LWS_CALLBACK_ESTABLISHED:
                pss->recive_all_from_client = 0;
                break;

        case LWS_CALLBACK_SERVER_WRITEABLE:
                
                if (pss->recive_all_from_client == 1)
                {
                        root = cJSON_CreateObject();
                        cJSON_AddItemToObject(root, "text", cJSON_CreateString(pss->text_string));
                        cJSON_AddItemToObject(root, "id", cJSON_CreateString(pss->id_string));
                        cJSON_AddItemToObject(root, "msg", cJSON_CreateString("Thanks!"));
                        resp_json = cJSON_Print(root);
                        n = sprintf((char *)pout, "%s", resp_json);
                        //m = lws_write(wsi, out, sizeof(out), LWS_WRITE_TEXT);
                        if (m < n) {
                                lwsl_err("ERROR %d writing to di socket\n", sizeof(out));
                                return -1;
                        }
                        /*
                        // Here i will keep the wsi and the user id in some vector or list 
                        */
                        
                        //Invoke response to selected users ... 
                }
                
                break;

        case LWS_CALLBACK_RECEIVE:
                if (len < 1)
                {
                        break;
                }
                lwsl_notice("Request from server: %s \n", (const char *)in);
                cJSON * user_root = cJSON_Parse((const char *)in);
                cJSON * user_type = cJSON_GetObjectItem(user_root, "type");
                cJSON * user_text = cJSON_GetObjectItem(user_root, "text");
                cJSON * user_id = cJSON_GetObjectItem(user_root, "id");
                cJSON * user_date = cJSON_GetObjectItem(user_root, "date");
                strcpy(pss->type_string, user_type->valuestring);
                strcpy(pss->text_string, user_text->valuestring);
                strcpy(pss->id_string, user_id->valuestring);
                strcpy(pss->date_string, user_date->valuestring);
                pss->recive_all_from_client = 1;
                 
                break;
                 
        case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:</span></font><br></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"><br></span></div><div><br></div></div>