Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <libwebsockets.h>
- int callback_http(struct libwebsocket_context *context,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason, void *user,
- void *in, size_t len)
- {
- 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
- },
- { NULL, NULL, 0, 0}
- };
- int main(void) {
- printf("Initializing Web Server\n");
- // server url will be http://localhost:8081
- int port = 8081;
- const char *interface = NULL;
- struct libwebsocket_context *context;
- // we're not using ssl
- const char *cert_path = NULL;
- const char *key_path = NULL;
- // no special options
- int opts = 0;
- struct lws_context_creation_info info;
- memset(&info, 0, sizeof info);
- info.port = port;
- info.iface = interface;
- info.protocols = protocols;
- info.extensions = libwebsocket_get_internal_extensions();
- info.ssl_cert_filepath = NULL;
- info.ssl_private_key_filepath = NULL;
- info.gid = -1;
- info.uid = -1;
- info.options = opts;
- context = libwebsocket_create_context(&info);
- if (context == NULL) {
- fprintf(stderr, "libwebsocket init failed\n");
- return 0;
- }
- printf("starting server...\n");
- while (1) {
- libwebsocket_service(context, 50);
- }
- printf("Shutting server down...\n");
- libwebsocket_context_destroy(context);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement