Comments (12)
excited
from mongoose.
That would be perfect for an implementation of live statics in my app : mooWApp Server
from mongoose.
I've implemented a first iteration of the functionality.
To see an example, checkout the code, then "cd examples && make && ./websocket"
Go to http://127.0.0.1:8080
It is crude at the moment. Client has to create, read and parse websocket frames on it's own.
Suggestions on the API are welcome.
from mongoose.
Thanks! I'll test it soon
from mongoose.
Thanks, this functionality will sure help me a lot.
The example code closes the connection just after sending a reply.
What should I do to keep the connection open? Returning a non-NULL value results in an infinite loop.
from mongoose.
Heh, that code wasn't supposed to have more than one round trip :-)
However, I've enhanced it and updated the example. Now it does two roundtrips, keeping the socket open after the initial message and closing only when "exit" message is received from the client.
Please let me know if it works for you. Again, as you can see in the example code, user must prepare and parse websocket frames. Mongoose has to provide a convenient API to do that, but I haven't come up with the nice API yet. If you have suggestions, please let me know.
from mongoose.
works exactly as I wanted, thank you very much!
from mongoose.
Hi! Thanks for this, I really need sockets for low latency UIs. I found it only worked with firefox, when I changed
!mg_strcasecmp(connection, "Upgrade");
to
!mg_strcasecmp(connection, "keep-alive, Upgrade");
in static int is_websocket_request(const struct mg_connection *conn). Sure this in an awful workaround, but you see where it's heading :-)
from mongoose.
Right, I see.
I've pushed
9313141,
which should make things better.
On Mon, Sep 24, 2012 at 12:10 AM, tzeH [email protected] wrote:
Hi! Thanks for this, I really need sockets for low latency UIs. I found it
only worked with firefox, when I changed!mg_strcasecmp(connection, "Upgrade");
to
!mg_strcasecmp(connection, "keep-alive, Upgrade");
in static int is_websocket_request(const struct mg_connection *conn). Sure
this in an awful workaround, but you see where it's heading :-)—
Reply to this email directly or view it on GitHubhttps://github.com//issues/27#issuecomment-8804074.
from mongoose.
This is excellent! I've wanted this with mongoose for, maybe even over 2 years now.
For the API, have you taken a look at libwebsocket?
I was using that in tandem with mongoose to achieve what I needed.
(making it actually a pretty decent headache to maintain)
There are a few desires, such as broadcasting messages to all or to specific connected clients in some form of main program loop (I am using it for a websocket/webgl video game server) - which also requires maintaining long-term connections to thousands of clients. (well hopefully thousands lol)
Fixed message lengths - it seems you're limiting to 126 bytes, or am I interpreting the code incorrectly?
Another thing I'm noticing, which is similar to what libwebsocket does, is that the client needs to assemble the complete websocket reply, including the pre and post padding, in your case, reply0-1
Anyway, perhaps all of this isn't really inline with what you intended mongoose for, in which case I am truly thankful for what you've built as it is. I have incorporated this code in several of my personal projects - greatly preferring it to any of the more complicated solutions. I seriously appreciate your efforts.
from mongoose.
Broadcasting can be easily done inside the callback by usual means: block waiters on condvar, wake them up on new message, send message.
There is no limitation on the message length in mongoose. There is a limitation in the example only. Mongoose code parses the frame and sets internal conn->content_len to the message length. Well, to be entirely precise, websocket's message length is uint64_t, and mongoose's content_len is int64_t -- two times smaller. In reality I think this is not an issue. As soon as mongoose code sets content_len, user's calls to mg_read will return new data until everything is read. The reason of the limitation in the example code is that I was lazy and didn't parse the frame properly (that would be a copy/paste from the mongoose's code), and left it that way until people suggest an API :-) This is also the reason that frames should be fully constructed in the user's code. I did not yet give enough thought to the good API.
from mongoose.
I think you just need a flag on the connection object that this is a websocket connection (or an enum for standard_connection, websocket_connection, external_connection (for user calls to mg_connection)). Then inside push() you can generate a websocket frame for websocket connections. Same thing for calls to pull(). On a websocket, it can read/verify the frame and strip it off for websocket connections.
Alternately, mg_write_msg and mg_read_msg defined as only working with websockets is another possibility, though that would still probably need the enum mentioned above.
from mongoose.
Related Issues (20)
- mg_queue_printf not setting correct queue size - what am I doing wrong? HOT 1
- Chunked message body incorrectly terminated on `\r\n\r\n` instead of `0\r\n\r\n`
- About running on a riscv-linux HOT 1
- MG_EV_CLOSE is fired before MG_EV_HTTP_MSG HOT 16
- RP2040 W5500 and DHCP HOT 14
- POST and TLS client HOT 11
- gcc warning in builtin TLS code HOT 2
- Unbounded growth in transmit buffer with WebSockets HOT 8
- Bus error crash in the new mg_wakeup() function HOT 4
- how to config in mbed ?
- Prefix PHY_* constants in STM32 drivers with MG_ to avoid name conflicts
- Rename MG_ENABLE_FILE to MG_ENABLE_POSIX_FS
- MG_ARCH_FREERTOS_LWIP is not available in Mongoose 7.12 HOT 1
- Mongoose documentation SSL/TLS tutorial is inaccurate for mg_tls_opts. HOT 2
- Mongoose prematurely closes connections when the second request in a pipeline is invalid
- Mongoose closes the connection without responding to POST requests that don't have explicit lengths HOT 2
- Discrepancy Between Mongoose Versions on Espressif Component Registry and Official Release HOT 1
- The maximum DNS response count should be a larger value HOT 1
- Mbedtls error and memory leak when connecting through WebSocket HOT 1
- Reading post data from https connection fails now and then HOT 24
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose.