From aa84636baf4468937431a22be095c8d283a940da Mon Sep 17 00:00:00 2001 From: aunterei Date: Thu, 11 May 2017 12:09:11 +0200 Subject: [PATCH] first commit --- Zozo/sc3/index.html | 32 ++++++++++++++++++++++++++++++++ Zozo/sc3/options.html | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Zozo/sc3/options.html~ | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Zozo/sc3/style.css | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 38 ++++++++++++++++++++++++++++++++++++++ server.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 413 insertions(+), 0 deletions(-) create mode 100755 Zozo/sc3/index.html create mode 100755 Zozo/sc3/options.html create mode 100755 Zozo/sc3/options.html~ create mode 100755 Zozo/sc3/style.css create mode 100644 index.html create mode 100644 server.c diff --git a/Zozo/sc3/index.html b/Zozo/sc3/index.html new file mode 100755 index 0000000..75b2f69 --- /dev/null +++ b/Zozo/sc3/index.html @@ -0,0 +1,32 @@ + + + +
+ + + PROJET SC + +
+ + + + + + +
+
TITRE
+
CONTENU: presentation du projet ...
+ + + + + + diff --git a/Zozo/sc3/options.html b/Zozo/sc3/options.html new file mode 100755 index 0000000..978628c --- /dev/null +++ b/Zozo/sc3/options.html @@ -0,0 +1,91 @@ + + +
+ + + PROJET SC +
+ + + + + + + + + + + +
+
+
+ +
CHOIX DES OPTIONS
+
+ + +
+ Lieu : + + + + + + + + +
+
+ + +
+
+ + + + + + + diff --git a/Zozo/sc3/options.html~ b/Zozo/sc3/options.html~ new file mode 100755 index 0000000..84b9a83 --- /dev/null +++ b/Zozo/sc3/options.html~ @@ -0,0 +1,73 @@ +#include +#include +#include + +static int callback_http(structlibwebsocket_context * this, + structlibwebsocket *wsi, + enumlibwebsocket_callback_reasons reason, void *user, + void *in, size_t len) +{ + return 0; +} + +
+ + + PROJET SC + +
+ + + + + + +
+
+
+ +
CHOIX DES OPTIONS
+
+ + +
+ Lieu : + + + +
+
+ + +
+
+ + + + +
+
+ + diff --git a/Zozo/sc3/style.css b/Zozo/sc3/style.css new file mode 100755 index 0000000..c87cb58 --- /dev/null +++ b/Zozo/sc3/style.css @@ -0,0 +1,73 @@ + +{ + border-bottom : 1px solid #9EA0A1; + padding-bottom : 25px; +} + +#onglets +{ + position : absolute; + border : 1px solid transparent; + padding : 0; + font : bold 11px Batang, arial, serif; + list-style-type : none; + left : 50%; + margin-top : 0; + width : 430px; + margin-left : -215px; /* la moiti� de width */ +} + +#onglets li +{ + float : left; + height : 23px; /* � modifier suivant la taille de la police pour centrer le texte dans l'onglet */ + background-color: RGB(245,245,245); + margin : 2px 2px 0 2px !important; /* Pour les navigateurs autre que IE */ + margin : 1px 2px 0 2px; /* Pour IE */ + border : 1px solid #9EA0A1; +} + +#onglets li.active +{ + border-bottom: 1px solid #fff; + background-color: #fff; +} + +#onglets a +{ + display : block; + color : #666; + text-decoration : none; + padding : 3px; +} + +#onglets a:hover +{ + background : #fff; +} + +.titre +{ + color : RGB(0,59,84); + font-size : 20px; + font-weight : bold; + text-align : center; +} + +.contenu +{ + text-align : center; +} + +/*a +{ + color: RGB(255,59,23); + font-size : 16px; + font-weight : bold; +}*/ + +* /*pour toute la page*/ +{ + font-size: 14px; +} + diff --git a/index.html b/index.html new file mode 100644 index 0000000..5c29536 --- /dev/null +++ b/index.html @@ -0,0 +1,38 @@ + + + + + + + + +

WebSockets test

+
+ + +
+
+ + diff --git a/server.c b/server.c new file mode 100644 index 0000000..55eac89 --- /dev/null +++ b/server.c @@ -0,0 +1,106 @@ +#include +#include +#include +#define MAX_FRAME_SIZE 1024 +#define WAIT_DELAY 50 + +static int callback_http(struct libwebsocket_context * this, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, void *user, + void *in, size_t len) +{ + return 0; +} + +static int callback_dumb_increment(struct libwebsocket_context * this, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, + void *user, void *in, size_t len) +{ + + switch (reason) { + case LWS_CALLBACK_ESTABLISHED: // just log message that someone is connecting + printf("connection established\n"); + break; + case LWS_CALLBACK_RECEIVE: { // the funny part + // create a buffer to hold our response + // it has to have some pre and post padding. You don't need to care + // what comes there, libwebsockets will do everything for you. For more info see + // http://git.warmcat.com/cgi-bin/cgit/libwebsockets/tree/lib/libwebsockets.h#n597 + unsigned char *buf = (unsigned char*) malloc(LWS_SEND_BUFFER_PRE_PADDING + len + + LWS_SEND_BUFFER_POST_PADDING); + + int i; + + // pointer to `void *in` holds the incomming request + // we're just going to put it in reverse order and put it in `buf` with + // correct offset. `len` holds length of the request. + for (i=0; i < len; i++) { + buf[LWS_SEND_BUFFER_PRE_PADDING + (len - 1) - i ] = ((char *) in)[i]; + } + + // log what we recieved and what we're going to send as a response. + // that disco syntax `%.*s` is used to print just a part of our buffer + // http://stackoverflow.com/questions/5189071/print-part-of-char-array + printf("received data: %s, replying: %.*s\n", (char *) in, (int) len, + buf + LWS_SEND_BUFFER_PRE_PADDING); + + // send response + // just notice that we have to tell where exactly our response starts. That's + // why there's `buf[LWS_SEND_BUFFER_PRE_PADDING]` and how long it is. + // we know that our response has the same length as request because + // it's the same message in reverse order. + libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], len, LWS_WRITE_TEXT); + + // release memory back into the wild + free(buf); + break; + } + default: + break; + } + + + return 0; +} + +static struct libwebsocket_protocols protocols[] = { + /* first protocol must always be HTTP handler */ + { + "http-only", // name + callback_http, // callback + 0 // per_session_data_size + }, + { + "dumb-increment-protocol", // protocol name - very important! + callback_dumb_increment, // callback + 0 // we don't use any per session data + + }, + { + NULL, NULL, 0 /* End of list */ + } +}; + + + +int main(void) { +int port=9000; +struct lws_context_creation_info info; +memset(&info,0,sizeof info); +info.port=port; +info.protocols=protocols; +info.gid=-1; +info.uid=-1; +struct libwebsocket_context *context=libwebsocket_create_context(&info); +if(context==NULL){ + fprintf(stderr, "libwebsocket init failed\n"); + return -1; + } +printf("starting server...\n"); +while(1){ + libwebsocket_service(context,WAIT_DELAY); + } +libwebsocket_context_destroy(context); +return 0; +} -- libgit2 0.21.2