Closed totszwai closed 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?
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
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
You mean during the connection acceptation phase, I need to response with a RFC6455 header to the client? Is there an example for that?
... 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.
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?
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;
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.
I confirmed the changes I suggested above work fine with 'the client ws example and libwebsockets-test-server
locally.
[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:
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
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".
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
...
Instructions
cmake . && make
Doesn't magically work.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:
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.