warmcat / libwebsockets

canonical libwebsockets.org networking library
https://libwebsockets.org
Other
4.74k stars 1.48k forks source link

None of the minimal-examples can be build following the instructions #1212

Closed totszwai closed 6 years ago

totszwai commented 6 years ago

Instructions cmake . && make Doesn't magically work.

cmake . && make -- Configuring done -- Generating done -- Build files have been written to: libwebsockets-master/minimal-examples/ws-server/minimal-ws-server Scanning dependencies of target lws-minimal-ws-server [ 50%] Building C object CMakeFiles/lws-minimal-ws-server.dir/minimal-ws-server.c.o libwebsockets-master/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c:17:27: fatal error: libwebsockets.h: No such file or directory compilation terminated. CMakeFiles/lws-minimal-ws-server.dir/build.make:62: recipe for target 'CMakeFiles/lws-minimal-ws-server.dir/minimal-ws-server.c.o' failed make[2]: [CMakeFiles/lws-minimal-ws-server.dir/minimal-ws-server.c.o] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/lws-minimal-ws-server.dir/all' failed make[1]: [CMakeFiles/lws-minimal-ws-server.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2

Then trying to copy the upper level include folder into the local folder, and messing with the CMakeLists.txt:

target_include_directories(${SAMP} PRIVATE "include")

Then it asks for the lwebsockets:

Scanning dependencies of target lws-minimal-ws-server [ 50%] Building C object CMakeFiles/lws-minimal-ws-server.dir/minimal-ws-server.c.o [100%] Linking C executable lws-minimal-ws-server /usr/bin/ld: cannot find -lwebsockets collect2: error: ld returned 1 exit status CMakeFiles/lws-minimal-ws-server.dir/build.make:94: recipe for target 'lws-minimal-ws-server' failed make[2]: [lws-minimal-ws-server] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/lws-minimal-ws-server.dir/all' failed make[1]: [CMakeFiles/lws-minimal-ws-server.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2

What's the proper steps to get this example to work? I'm trying to run a test against the minimal-ws-server example because I couldn't get libwebsockets to accept a simple ws connection.

lws-team commented 6 years ago

fatal error: libwebsockets.h: No such file or directory

You shouldn't need to mess with anything, unpick your changes with git reset --hard.

Did you read this?


FAQ Getting started

Build and install lws itself first (note that after installing lws on *nix, you need to run ldconfig one time so the OS can learn about the new library. Lws installs in /usr/local by default, Debian / Ubuntu ldconfig knows to look there already, but Fedora / CentOS need you to add the line /usr/local/lib to /etc/ld.so.conf and run ldconfig)


Did you build and install lws? Where to?

totszwai commented 6 years ago

Got it, thanks. Slightly more complicate lol...

Added entry in /etc/ld.so.conf Restarted shell Rebuild the whole libwebsockets with cmake . Then make && sudo make install Then build the example and ran it with LD_LIBRARY_PATH=/usr/local/lib/ ./lws-minimal-ws-server &

I am trying to test why I couldn't accept a websocket connection using libwebsockets. Which lead me to this:

LD_LIBRARY_PATH=/usr/local/lib/ ./lws-minimal-ws-server & curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: localhost" -H "Origin: http: //localhost" http://localhost:7681 [2018/03/20 09:36:10:7056] NOTICE: Unknown client spec version 0 [2018/03/20 09:36:10:7057] NOTICE: hs0405 has failed the connection curl: (52) Empty reply from server

Can you share some insight? https://stackoverflow.com/questions/49371822/how-do-you-accept-websocket-connection-with-libwebsockets

lws-team commented 6 years ago

OK... so there is no problem "building the examples following the instructions"... you didn't "follow the instructions".

You can't "make a ws connection using libwebsockets" because you don't follow RFC 6455 when assembling the header by hand :-( that's nothing to do with lws

https://tools.ietf.org/html/rfc6455#section-11.3.5

totszwai commented 6 years ago

You mean during the connection acceptation phase, I need to response with a RFC6455 header to the client? Is there an example for that?

lws-team commented 6 years ago

... If you want to make a ws connection, you must follow RFC6455, of course.

You cannot do that by hand with curl, it has a special dance with sha1 computations that is checked by the server.

I don't know what you're trying to do but the way you are going about it won't work. Lws supports both client and server sides of ws maybe that can help. Or maybe not.

lws-team commented 6 years ago

Minimal client example

https://github.com/warmcat/libwebsockets/tree/master/minimal-examples/ws-client/minimal-ws-client-rx

totszwai commented 6 years ago

Yes, I know the client code worked, I've tried to play with it already. I'm just having trouble setting up the server side to accept the connection.

Here I tried to setup your minimal-ws-server to talk to the minimal-ws-client, I've disabled ssl, and change the port to 7681 like the server:

LD_LIBRARY_PATH=/usr/local/lib/ ./lws-minimal-ws-client-rx [2018/03/20 09:56:38:5574] USER: LWS minimal ws client rx [2018/03/20 09:56:38:5575] NOTICE: Creating Vhost 'default' port -1, 1 protocols, IPv6 off [2018/03/20 09:56:38:5577] NOTICE: No protocol from "dumb-increment-protocol" supported [2018/03/20 09:56:38:5578] ERR: CLIENT_CONNECTION_ERROR: read failed [2018/03/20 09:56:38:5579] USER: Completed

Which magical ws server/example is running on libwebsockets.org:443?

lws-team commented 6 years ago

You sound like maybe you are in too much of a rush. Each of the problems you mention here are down to either not understanding ws enough or not trying to find out how the lws pieces go together.

When you built lws unless you messed with the default cmake config, it will have built libwebsockets-test-server. Just run that and it will listen on localhost:7681 without tls, and provide "dumb-increment-protocol". You can adapt the example client like this (untested)

    i.port = 7681;
    i.address = "localhost";
    i.path = "/";
    i.host = i.address;
    i.origin = i.address;
        i.ssl_connection = 0;
totszwai commented 6 years ago

I already made those changes you mentioned before I post my previous comment. I'm simply trying to understand your libwebsockets via your provided examples.

I even commented out: //info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;

Your client examples are easy to understand, but not the server part.

lws-team commented 6 years ago

I confirmed the changes I suggested above work fine with 'the client ws example and libwebsockets-test-serverlocally.

[2018/03/20 09:56:38:5577] NOTICE: No protocol from "dumb-increment-protocol" supported

You seem to be trying to connect it to something that doesn't offer 'dumb-increment-protocol'... why don't you take a minute and look at RFC6455 about Sec-Websocket-Protocol, eg https://tools.ietf.org/html/rfc6455#section-1.3

LD_LIBRARY_PATH=/usr/local/lib/ ./lws-minimal-ws-client-rx

There is no need to do that, just slow down a bit follow exactly what it says in the FAQ I pasted:


Build and install lws itself first (note that after installing lws on *nix, you need to run ldconfig one time so the OS can learn about the new library. Lws installs in /usr/local by default, Debian / Ubuntu ldconfig knows to look there already, but Fedora / CentOS need you to add the line /usr/local/lib to /etc/ld.so.conf and run ldconfig)

These steps are related to adding any library in *nix, they are not specific to lws.

Your client examples are easy to understand, but not the server part.

What do you find difficult to understand about the minimal ws server example, eg,

https://github.com/warmcat/libwebsockets/tree/master/minimal-examples/ws-server/minimal-ws-server

totszwai commented 6 years ago

I already did the steps mentioned in the FAQ. I am just trying to understand how it works. Because I compiled the minimal-ws-server with LLL_INFO and LLL_DEBUG. Then used the following command to just try to connect to it:

curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: localhost" -H "Origin: http://localhost" -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" -H "Sec-WebSocket-Versi on: 13" http://localhost:7681

And I see this:

HTTP/1.1 101 Switching Protocols Upgrade: WebSocket Connection: Upgrade Sec-WebSocket-Accept: qGEgH3En71di5rrssAZTmtRTyFk=

^C[2018/03/21 09:58:15:3809] NOTICE: lws_service_fd_tsi: zero length read

And I see nothing from the server side that prints anything such as connected or what not... So I am not sure if it is actually connected and/or the connection had been accepted.

I am trying to understands how your server example works, because I am writing a ws server that interface with an existing ws client that uses your libwebsockets, this client when connected to a python script that simulate a ws server, "it works". But when I try to connect to my ws server that runs your minimal-ws-server code (as a test), it doesn't. The connection was never accepted.

Again, I am not saying your example "doesn't work", I am just trying to understands it... maybe the client code is broken and the python ws just magically "work".

lws-team commented 6 years ago

As it says in READMEs/README.build.md


NOTE5: To build with debug info and _DEBUG for lower priority debug messages compiled in, use

$ cmake .. -DCMAKE_BUILD_TYPE=DEBUG

For release builds the more verbose messages are removed from the build.

And I see nothing from the server side that prints anything such as connected or what not...

Add a log on the ESTABLISHED callback if you want to know about it.

...and read about ./ send Sec-Websocket-Protocol...