Ich bin Deborah.
Schaut euch meine Arbeiten
an oder lest meinen Blog.

Ubuntu 12.10, libwebsockets and OF

(English) This is a leaflet on how to compile libwebsockets under Ubuntu 12.10. The second part describes my steps to successfully compile and partially run the openFrameworks addon ofxLibwebsockets.

Installation and test of libwebsockets [source]

  • Download, configuration and installation:
    sudo apt-get install autoconf libtool
    git clone git://git.warmcat.com/libwebsockets
    cd libwebsockets/
    automake --add-missing
    autoreconf
    libtoolize
    ./configure --prefix=/usr
    make
    sudo make install
  • Test:
    libwebsockets-test-server
  • → open your favourite browser and enjoy libwebsockets running on URL http://localhost:7681/.

Browser compatibility of WebSockets

While Chrome and Firefox showed the libwebsocket test page correctly, I had no luck with Opera (v12.02). This is caused by Operas restricted use of WebSockets. You can enable it by opening opera:config with Opera. Expand the list called „User Prefs“ and check „Enable WebSockets“.
See caniuse.com for a list of different browser compatibilities regarding Web Sockets.

OpenFrameworks v0071 and ofxLibwebsockets

Download the code

  • Open the addon folder of your OpenFrameworks installationcd addons
  • Download the addon for libwebsockets. With the main branch I had a segmentation fault in the end, that’s why I got the windows-fix branch recommended.git clone -b windows-fix https://github.com/labatrockwell/ofxLibwebsockets.git

Compiling the ServerEcho example

  • Copy the server example to the addons example folder and go to that locationcp -R ofxLibwebsockets/example-server-echo/ ../examples/addons/libwebsocketsServerEchoExample
    cd ../examples/addons/libwebsocketsServerEchoExample/
  • Generate the project files for your systemprojectGenerator .
  • When I compiled the project with „make“, it resulted in a bunch of errors:/usr/include/c++/4.7/ctime:62:11: error: ‘::clock_t’ has not been declared
    /usr/include/c++/4.7/ctime:63:11: error: ‘::time_t’ has not been declared
    /usr/include/c++/4.7/ctime:64:11: error: ‘::tm’ has not been declared

    This is happening because of a name clash, caused by a file in the addons „lib“-folder for Windows. I just deleted it to get rid of the error. There may be a better way to assure compilation under Windows will continue working.. rm -R ../../../addons/ofxLibwebsockets/libs/libwebsockets/include/win32port/
  • The next error is fixed in the above mentioned branch. Nevertheless, you could be faced with the following when running „make“: src/testApp.cpp:89:23: error: conversion from ‘long int’ to ‘const Json::Value’ is ambiguousTo fix this, do the following:
    • gedit ../../../addons/ofxLibwebsockets/libs/ofxLibwebsockets/src/Reactor.cpp &
    • Change the lines 106 and 114 like this and save it://before:
      //args.json = NULL;
      args.json = Json::Value::null;
    • gedit src/testApp.cpp &
    • Change line 89 like this and save it://before:
      //if ( args.json != NULL){
      if ( args.json != Json::Value::null){
  • Next error to cope with when running „make“:../../../addons/ofxLibwebsockets/libs/libwebsockets/include/libwebsockets.h:425:20: error: ‘size_t’ has not been declared
    • gedit ../../../addons/ofxLibwebsockets/libs/libwebsockets/include/libwebsockets.h
    • Insert at line 52:#else
      #include <poll.h>
      #include <stdlib.h>
      #endif
  • My last errors were related to the missing compiled libwebsockets library for Linux 64bit:Protocol.cpp:(.text+0x11f): undefined reference to `libwebsockets_broadcast'
    Reactor.cpp:(.text+0xc5): undefined reference to `libwebsocket_context_destroy'
    ..

    If you installed the library like described in the first part of this article, this is easy to fix.

    • gedit config.make &
    • Insert this line:USER_LIBS = -lwebsockets
  • Now you should be able to compile the example:make

Testing the server

cd bin
./libwebsocketsServerEchoExample

Clicking anywhere on the window, it opens a website where you can test the service. In my case this worked in Chromium, but not in Firefox.
At first, the program was crushing:Compiled without SSL support, serving unencrypted
Listening on port 9092
Created new window in existing browser session.
Segmentation fault (core dumped)
This is fixed by the above mentioned branch windows-fix.

Testing the client

When I run the ClientHelloWorld example and connect it to „echo.websocket.org“ by commenting in the regarding line in „src/testApp.cpp“, it’s not working:libwebsocket init success
client connection success
ERROR writing to socket
..
ERROR writing to socket
lws_client_interpret_server_handshake: NULL c_protocol
lws_client_interpret_server_handshake WSI_TOKEN_PROTOCOL is null
on close

The segmentation fault appears at line 690 in „libwebsockets/lib/libwebsockets.c“:
context->protocols[0].callback(context, wsi,
LWS_CALLBACK_CLEAR_MODE_POLL_FD,
(void *)(long)wsi->sock, NULL, POLLOUT);

Kommentare

  1. Anonymous 2. März 2013 at 4:35 am Antworten

    Thank you so much! This is the ONLY tutorial I’ve found on how to install libwebsockets. Future readers should install this first: http://askubuntu.com/questions/210598/how-to-install-zlib-libgcrypt-using-apt-get I also installed gcc. Don’t know if that made a difference.

Sag etwas

Deine email-Adresse wird nicht veröffentlicht.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Artikel zum Thema "Blog":

(English) The Art of Coding(English) Imperfect Mandalas(English) Autumn Leafs(English) Color Explosion #25 Jahre KAZOOSH!FarbexplosionUbuntu 15.10, MongoDB und node.jsSpeed of Fencing Remixgit cheat sheetFraktaleofxSortableListHäkeln: Haarband mit JeansknopfWandmalen zu Marias GeburtstagLinux / Ubuntu + Serato Vinyl Control System + Pure DataWicket-Bootstrap – Navbar und Pageparameters – aktives Item setzenLinux Console MerkzettelCrawling Traces @Deutscher Multimediapreis mb21Crawling Traces History Viewernew.livestream.com unter Ubuntu mit VLC abspielenCrawling Traces at Hechtfest / hechtgruenLinksammlung: Datensicherheit, soziale Netzwerke und sicheres MailingFix: VMware Player Crash unter Ubuntu 13.04Xubuntu: Wenn Dockbarx Thunar oder das Terminal nicht startet.Ubuntu 12.10, libwebsockets and OFSetting up Meteor with Ubuntu 12.10 on an NTFS share partitionWebauftritt: KAZOOSH!Zwischenstand IsolinienDas Scheunentor wird buntSkype auf Ubuntu 10.10 oder 11.04 64bitElitebook 8440p vs UbuntuKryptografie & Datensicherheit – NotizenRandom Compilation IIRandom Compilation IAll You Can Eat in DresdenWebauftritt: ESE 2010