serveur_minitel_web
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
serveur_minitel_web [2019/06/19 11:33] – [Openframeworks] Mushussu | serveur_minitel_web [2020/04/13 12:52] (Version actuelle) – Mushussu | ||
---|---|---|---|
Ligne 15: | Ligne 15: | ||
Installer LibWebSocket : | Installer LibWebSocket : | ||
- | cd | + | [[serveur_websocket|Installation de LibWebSockets]] |
- | git clone https:// | + | |
- | cd libwebsockets | + | |
- | mkdir build | + | |
- | cd build | + | |
- | cmake .. -DLWS_IPV6=OFF | + | |
- | make && sudo make install | + | |
Ligne 32: | Ligne 25: | ||
Configurer sa box : | Configurer sa box : | ||
- | https:// | + | [[labom_yunohost_sur_raspberrypi# |
LibWebSockets | LibWebSockets | ||
- | https:// | + | [[https:// |
- | {{tag> | + | |
+ | LibWebSockets en C++ | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | <code c> | ||
+ | // gcc -Wall testServeur.c -o testServeur -lwebsockets | ||
+ | |||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | static int | ||
+ | lws_callback_http( | ||
+ | |||
+ | struct lws *wsi, | ||
+ | enum lws_callback_reasons reason, | ||
+ | void *user, | ||
+ | void *in, | ||
+ | size_t len | ||
+ | ) { | ||
+ | switch (reason) { | ||
+ | case LWS_CALLBACK_ESTABLISHED: | ||
+ | printf(" | ||
+ | break; | ||
+ | case LWS_CALLBACK_RECEIVE: | ||
+ | unsigned char *buf = (unsigned char*) | ||
+ | malloc(LWS_SEND_BUFFER_PRE_PADDING + len | ||
+ | + LWS_SEND_BUFFER_POST_PADDING); | ||
+ | int i; | ||
+ | for (i=0; i < len; i++) { | ||
+ | buf[LWS_SEND_BUFFER_PRE_PADDING + (len - 1) - i ] = | ||
+ | ((char *) in)[i]; | ||
+ | } | ||
+ | |||
+ | printf(" | ||
+ | (int) len, buf + LWS_SEND_BUFFER_PRE_PADDING); | ||
+ | |||
+ | lws_write(wsi, | ||
+ | len, LWS_WRITE_TEXT); | ||
+ | free(buf); | ||
+ | break; | ||
+ | } | ||
+ | default: | ||
+ | break; | ||
+ | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | static struct lws_protocols protocols[] = { | ||
+ | { | ||
+ | " | ||
+ | lws_callback_http, | ||
+ | 0 // per_session_data_size | ||
+ | }, | ||
+ | { | ||
+ | NULL, NULL, 0 /* End of list */ | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | static const struct lws_extension exts[] = { | ||
+ | { | ||
+ | " | ||
+ | lws_extension_callback_pm_deflate, | ||
+ | " | ||
+ | }, | ||
+ | { NULL, NULL, NULL /* terminator */ } | ||
+ | }; | ||
+ | |||
+ | int main(void) { | ||
+ | int port = 9000; | ||
+ | const char *interface = NULL; | ||
+ | struct lws_context *context; | ||
+ | int opts = 0; | ||
+ | |||
+ | // create libwebsocket context representing this server | ||
+ | struct lws_context_creation_info info; | ||
+ | |||
+ | memset(& | ||
+ | info.port = port; | ||
+ | info.iface = interface; | ||
+ | info.protocols = protocols; | ||
+ | info.extensions = exts; | ||
+ | //if (!use_ssl) { | ||
+ | info.ssl_cert_filepath = NULL; | ||
+ | info.ssl_private_key_filepath = NULL; | ||
+ | //} else { | ||
+ | // info.ssl_cert_filepath = LOCAL_RESOURCE_PATH"/ | ||
+ | // info.ssl_private_key_filepath = LOCAL_RESOURCE_PATH"/ | ||
+ | //} | ||
+ | info.gid = -1; | ||
+ | info.uid = -1; | ||
+ | info.options = opts; | ||
+ | |||
+ | context = lws_create_context(& | ||
+ | |||
+ | if (context == NULL) { | ||
+ | fprintf(stderr, | ||
+ | return -1; | ||
+ | } | ||
+ | |||
+ | printf(" | ||
+ | while (1) { | ||
+ | lws_service(context, | ||
+ | } | ||
+ | |||
+ | lws_context_destroy(context); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | Compiler le tout : | ||
+ | gcc -Wall serveurWebsocket.c -o serveurWebsocket -lwebsockets | ||
+ | |||
+ | sudo ldconfig | ||
+ | ./ | ||
+ | |||
+ | | ||
+ | {{tag> |
serveur_minitel_web.1560943995.txt.gz · Dernière modification : 2019/06/19 11:33 de Mushussu