Advertisement
Guest User

Untitled

a guest
Nov 13th, 2013
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <libwebsockets.h>
  5.  
  6.  
  7. int callback_http(struct libwebsocket_context *context,
  8.                          struct libwebsocket *wsi,
  9.                          enum libwebsocket_callback_reasons reason, void *user,
  10.                          void *in, size_t len)
  11. {
  12.     return 0;
  13. }
  14.  
  15. static struct libwebsocket_protocols protocols[] = {
  16.     /* first protocol must always be HTTP handler */
  17.     {
  18.         "http-only",   // name
  19.         callback_http, // callback
  20.         0              // per_session_data_size
  21.     },
  22.     { NULL, NULL, 0, 0}
  23. };
  24.  
  25. int main(void) {
  26.     printf("Initializing Web Server\n");
  27.         // server url will be http://localhost:8081
  28.     int port = 8081;
  29.     const char *interface = NULL;
  30.     struct libwebsocket_context *context;
  31.     // we're not using ssl
  32.     const char *cert_path = NULL;
  33.     const char *key_path = NULL;
  34.     // no special options
  35.     int opts = 0;
  36.  
  37.  
  38.     struct lws_context_creation_info info;
  39.  
  40.     memset(&info, 0, sizeof info);
  41.     info.port = port;
  42.     info.iface = interface;
  43.     info.protocols = protocols;
  44.     info.extensions = libwebsocket_get_internal_extensions();
  45.     info.ssl_cert_filepath = NULL;
  46.     info.ssl_private_key_filepath = NULL;
  47.     info.gid = -1;
  48.     info.uid = -1;
  49.     info.options = opts;
  50.  
  51.     context = libwebsocket_create_context(&info);
  52.     if (context == NULL) {
  53.         fprintf(stderr, "libwebsocket init failed\n");
  54.         return 0;
  55.     }
  56.  
  57.     printf("starting server...\n");
  58.  
  59.     while (1) {
  60.         libwebsocket_service(context, 50);
  61.     }
  62.     printf("Shutting server down...\n");
  63.     libwebsocket_context_destroy(context);
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement