mnisjk / cppwebsockets Goto Github PK
View Code? Open in Web Editor NEWA simple, lightweight c++ WebSockets server library
License: Other
A simple, lightweight c++ WebSockets server library
License: Other
Hi @mnisjk,
I really liked the simplicity of this wrapper and it really solved some of the issues i have been having . Kudos to you and the rest of the contributors!
I was wondering if it is possible to use your project in a commercial project. You specifically mention in LICENSE.md that this is a wrapper around libwebsockets ( which is under lgpl ). So i'm confused whether i can use it in a commercial project.
g++ -w -DLOG_TO_STDOUT=1 -oechoserver ../../Util.cpp ../../WebSocketServer.cpp echoServer.cpp -lwebsockets
../../WebSocketServer.cpp: In constructor ‘WebSocketServer::WebSocketServer(int, std::string, const string&)’:
../../WebSocketServer.cpp:99:23: error: ‘lws_get_internal_extensions’ was not declared in this scope
99 | info.extensions = lws_get_internal_extensions( );
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:2: hellomake] Error 1
Steps to reproduce:
On one system (ubuntu 16.04), it crashes with strings of length 16, like "1234567890123456", on another (yocto on intel edison) after 128 characters.
This does not happen with the libwebsockets-test-echo, so I assume it is something with cppWebSockets. Any idea?
It works so far.
Have to dig into it anyway the next days.
Thanks for your work.
git clone git://git.libwebsockets.org/libwebsockets
The above no longer works. Maybe it's moved to some other place?
the cppWebSocket is using too much CPU (about 70%) in my embedded board (ARM v7 with 251M of RAM) . I just had to modify some lines in the code and I get nearly 0% of CPU usage.
Needed some fixes with the performance ;)
I implemented a simple build and install using cmake (I don't pretend to be a CMake guru; but it works for me).
CMakeLists.txt
I've only tested on Linux; but I expect it to work on other platforms that support CMake. I didn't update the examples to use CMakeLists.txt as the Makefile(s) provided are simple enough.
If a device is disconnected, the program calls "broadcast" function. While calling this function it crashes.
The error shows:
double free or corruption (out): 0x01114358 ***
Aborted
I downloaded the code, and the examples didn't work.
I located what I think is an error in the buffer management.
The data type for the data waiting to be sent shouldn't be const char *, but strings.
struct Connection
{
list<string> buffer; // <-- string and not const char*
map<string,string> keyValueMap;
time_t createTime;
};
`
A copy of the incoming data should be made when pushing to the buffer:
A const char is just a pointer. If a pointer is pushed onto the buffer, and the pointer is for some reason no longer valid, then the buffer contains ... invalid data.
That's what I found when I put some debug statements into the code.
Here is what the echo server told me:
[cppWebSockets] Callback Receive
[cppWebSockets] Received: hjghjk
[cppWebSockets] send, socketID = 8 data = 'hjghjk'
[cppWebSockets] Callback Server Writeable, fd = 8
[cppWebSockets] == Elements in buffer: 1
[cppWebSockets] == Element :���� [cppWebSockets] Sending '
����'
The buffer elements was first pushed to the buffer in the WebSocketServer::send, and when the callback receive function asked for them, they were no longer valid.
Changing the datatype to string as shown solved the problem.
Just tested the echoserver with both libwebsocket v1.7.2 and libwebsocket v1.7-stable. I get a segfault on the first message reception. Here is my output:
$ ./echoserver
[cppWebSockets] Not using SSL
[cppWebSockets] Server started on port 8080
[cppWebSockets] New connection
[cppWebSockets] Received: asdasd
[cppWebSockets] Error: Error writing to socket on socketID '8'
[cppWebSockets] Error: Error writing to socket
Segmentation fault (core dumped)
per warmcat/libwebsockets#1255
https://libwebsockets.org/lws-api-doc-main/html/md_READMEs_README_8coding.html
The receive buffer size in lws_protocols could be increased or the user parameter could be used per the link above. Neither of these approaches is very attractive in terms of preserving the general structure of the library.
In addition, the wait() method calls lws_service w/ a timeout that has been obsoleted blocking until a connection is made.
How does this compare to Beast, which offers WebSocket and HTTP implementations?
http://vinniefalco.github.io/
Hey,
While working on a project that streams large JSON packets of sensor data, I noticed memory usage increasing slowly over time.
I ran through valgrind and it wouldn't find the error, since it wasn't a heap memory leak.
Eventually I found that passing in a c string, and changing all the send related functions to meet this fixed the issue.
I've submitted a PR with the changes I've made for you to look over.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.