src/libs/ulfius/lib_websocket.c
/**
 * websocket_manager_callback
 * send 5 text messages and 1 ping for 11 seconds, then closes the websocket
 */
websocket_manager_callback
send 5 text messages and 1 ping for 11 seconds, then closes the websocket
websocket_manager_callback send 5 text messages and 1 ping for 11 seconds then closes the websocket
void websocket_manager_callback(const struct _u_request * request,
                               struct _websocket_manager * websocket_manager,
                               void * websocket_manager_user_data) {
  if (websocket_manager_user_data != NULL) {
    dbgprintf(DBG_DEBUG, "websocket_manager_user_data is %s", websocket_manager_user_data);
  }
  if (ulfius_websocket_wait_close(websocket_manager, 2000) == U_WEBSOCKET_STATUS_OPEN) {
    if (ulfius_websocket_send_message(websocket_manager, U_WEBSOCKET_OPCODE_TEXT, o_strlen("Message without fragmentation from server"), "Message without fragmentation from server") != U_OK) {
      dbgprintf(DBG_ERROR, "Error send message without fragmentation");
    }
  }
  if (o_strncmp(u_map_get(request->map_header, "User-Agent"), U_WEBSOCKET_USER_AGENT, o_strlen(U_WEBSOCKET_USER_AGENT)) == 0 &&
      ulfius_websocket_wait_close(websocket_manager, 2000) == U_WEBSOCKET_STATUS_OPEN) {
    if (ulfius_websocket_send_fragmented_message(websocket_manager, U_WEBSOCKET_OPCODE_TEXT, o_strlen("Message with fragmentation from server"), "Message with fragmentation from server", 5) != U_OK) {
      dbgprintf(DBG_ERROR, "Error send message with fragmentation");
    }
  }
  if (ulfius_websocket_wait_close(websocket_manager, 2000) == U_WEBSOCKET_STATUS_OPEN) {
    if (ulfius_websocket_send_message(websocket_manager, U_WEBSOCKET_OPCODE_PING, 0, NULL) != U_OK) {
      dbgprintf(DBG_ERROR, "Error send ping message");
    }
  }
  if (ulfius_websocket_wait_close(websocket_manager, 2000) == U_WEBSOCKET_STATUS_OPEN) {
    if (ulfius_websocket_send_message(websocket_manager, U_WEBSOCKET_OPCODE_BINARY, o_strlen("Message without fragmentation from server"), "Message without fragmentation from server") != U_OK) {
      dbgprintf(DBG_ERROR, "Error send binary message without fragmentation");
    }
  }
  dbgprintf(DBG_DEBUG, "Closing websocket_manager_callback");
}
void websocket_manager_callback ( const struct _u_request * request , struct _websocket_manager * websocket_manager , void * websocket_manager_user_data ) { if ( websocket_manager_user_data != NULL ) { dbgprintf ( DBG_DEBUG , " " , websocket_manager_user_data ) ; } if ( ulfius_websocket_wait_close ( websocket_manager , 2000 ) == U_WEBSOCKET_STATUS_OPEN ) { if ( ulfius_websocket_send_message ( websocket_manager , U_WEBSOCKET_OPCODE_TEXT , o_strlen ( " " ) , " " ) != U_OK ) { dbgprintf ( DBG_ERROR , " " ) ; } } if ( o_strncmp ( u_map_get ( request -> map_header , " " ) , U_WEBSOCKET_USER_AGENT , o_strlen ( U_WEBSOCKET_USER_AGENT ) ) == 0 && ulfius_websocket_wait_close ( websocket_manager , 2000 ) == U_WEBSOCKET_STATUS_OPEN ) { if ( ulfius_websocket_send_fragmented_message ( websocket_manager , U_WEBSOCKET_OPCODE_TEXT , o_strlen ( " " ) , " " , 5 ) != U_OK ) { dbgprintf ( DBG_ERROR , " " ) ; } } if ( ulfius_websocket_wait_close ( websocket_manager , 2000 ) == U_WEBSOCKET_STATUS_OPEN ) { if ( ulfius_websocket_send_message ( websocket_manager , U_WEBSOCKET_OPCODE_PING , 0 , NULL ) != U_OK ) { dbgprintf ( DBG_ERROR , " " ) ; } } if ( ulfius_websocket_wait_close ( websocket_manager , 2000 ) == U_WEBSOCKET_STATUS_OPEN ) { if ( ulfius_websocket_send_message ( websocket_manager , U_WEBSOCKET_OPCODE_BINARY , o_strlen ( " " ) , " " ) != U_OK ) { dbgprintf ( DBG_ERROR , " " ) ; } } dbgprintf ( DBG_DEBUG , " " ) ; }
websocket_manager_callback
 send 5 text messages and 1 ping for 11 seconds, then closes the websocket
websocket_manager_callback send 5 text messages and 1 ping for 11 seconds then closes the websocket
// Send text message without fragmentation // Send text message with fragmentation for ulfius clients only, browsers seem to dislike fragmented messages // Send ping message // Send binary message without fragmentation