Comments (15)
I'd like more informations please, starting with the system you're using (processor, OS, version), and more information on the problem itself. what text payload are you talking about? The one on the browser? the one on the websocket_example console? somewhere else?
what do you mean when you say "some data have been received"?
Thanks in advance for the precisions
from ulfius.
I work on an advanced replica of a raspberry Pi:
Architecture: armv7l
Byte Order: Little Endian
CPU(s): 4
Model name: ARMv7 Processor Rev 4 (v7l)
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 8.0 (jessie)
Release: 8.0
codename: jessie
The issue happens when you try to send a message from the browser interface (index.html) to the websocket. I had to modify first the example so the websocket doesn't close after sending its 5 messages to the client. So I try to send a simple word "test" writing it in the browser text box and then clicking on the send button.
I see in the console logs that the programs entry the websocket_incoming_message_callback function.
I get the following info about the message: opcode: 1, has_mask: 1, data_len: 4 (that match the word size of what I'm trying to send).
But, the message data is empty: text payload ''
from ulfius.
In websocket_manager_callback
, when the 5 iterations are complete the function returns, so the websocket is closed by Ulfius: https://github.com/babelouest/ulfius/blob/master/API.md#starting-a-websocket-communication
When you say you had to modify the example so the websocket doesn't close after sending its 5 messages to the client
, what is the nature of your modification?
Because if the function websocket_manager_callback
ends, the behaviour may be undefined.
To avoid automatic websocket close by the server, you can either change the loop into for (i=0;; i++) {
or add a getchar();
at the end of the loop to pause the program.
from ulfius.
Yes, that's what I did.
Actually more dirty: while(1) {...
from ulfius.
can you post your updated websocket_manager_callback
? I'll try to reproduce your bug.
from ulfius.
There is just the "while" modification.
`void websocket_manager_callback(const struct _u_request * request,
struct _websocket_manager * websocket_manager,
void * websocket_manager_user_data) {
int i, ret;
char * my_message = (char *)websocket_manager_user_data;
if (my_message != NULL) {
y_log_message(Y_LOG_LEVEL_DEBUG, "websocket_manager_user_data is %s", my_message);
}
//for (i=0; i<5; i++) {
while(1) {
i++;
i=i%256;
sleep(2);
if (websocket_manager != NULL && websocket_manager->connected) {
my_message = msprintf("Send message #%d", i);
ret = ulfius_websocket_send_message(websocket_manager, U_WEBSOCKET_OPCODE_TEXT, o_strlen(my_message), my_message);
o_free(my_message);
if (ret != U_OK) {
y_log_message(Y_LOG_LEVEL_DEBUG, "Error send message");
break;
}
if (i == 2) {
ret = ulfius_websocket_send_message(websocket_manager, U_WEBSOCKET_OPCODE_PING, 0, NULL);
if (ret != U_OK) {
y_log_message(Y_LOG_LEVEL_DEBUG, "Error send ping message");
break;
}
sleep(1);
}
} else {
y_log_message(Y_LOG_LEVEL_DEBUG, "websocket not connected");
break;
}
}
y_log_message(Y_LOG_LEVEL_DEBUG, "Closing websocket_manager_callback");
}
But why do you think the issue comes from the
websocket_manager_callback? Should it be in the
websocket_incoming_message_callback`?
from ulfius.
I'm not sure actually where it comes from, I try to get all the information I need to reproduce the bug, and the only change you told me is in the websocket_incoming_message_callback
function.
from ulfius.
So far I can't reproduce this bug, I transformed the for
loop into an infinite loop but I still receive the messages in the websocket_incoming_message_callback
function.
from ulfius.
What doo you mean when you say "advanced replica of a raspberry Pi"? Is it a physical machine or a VM? Which one?
Also, what compiler are you using? How to you build Ulfius to run the tests?
from ulfius.
Actually it's a bit more complicated.
It's an ARMv7 running Raspbian. But you application is running in a docker container.
Fun project :-)
I am using the standard GCC compiler for ARM.
Here is a screenshot of websocket logs.
You can see that the incoming message (test payload)
is not displayed....
from ulfius.
I've been into the u_websocket.c file in order to track the issue.
I added some logs messages, but they don't show up when I run the test.
What do I have to do in order to access such logs?
from ulfius.
The logs are provided by yder
, a sublibrary, basically, yder builds a string with sprintf
and puts it in the console, a file or syslog. You can replace it with a simple printf
with the additional \n
at the end.
The code that logs the incoming message is the following:
y_log_message(Y_LOG_LEVEL_DEBUG, "text payload '%.*s'", last_message->data_len, last_message->data);
You can try the following lines instead to check where the problem would be.
// Check if the problems comes from yder by not using it
printf("text payload '%.*s'\n", last_message->data_len, last_message->data);
// Check if the problem comes from the `%.*s` format (not likely but worth a shot)
printf("text payload at %p '%s'\n", last_message->data, last_message->data);
// Finally, print out what's inside the first bytes of last_message->data
// Careful with this last one, the incoming message must be at least 3 characters long
printf("text payload %02x %02x %02x %02x\n", last_message->data[0], last_message->data[1], last_message->data[2], last_message->data[3]);
If you want to debug directly the websocket incoming message manager, check the function ulfius_read_incoming_message. More precisely, the payload is set starting line 291 if I recall correctly: https://github.com/babelouest/ulfius/blob/fix-websockets/src/u_websocket.c#L291
from ulfius.
ok so I put some logs in the u_websocket.c and the data are well displayed in the logs.
And it turns out that I have issue when I let:
y_log_message(Y_LOG_LEVEL_DEBUG, "text payload '%.*s'", last_message->data_len, last_message->data);
But the data are well displayed when I change it into:
y_log_message(Y_LOG_LEVEL_DEBUG, "text payload '%s'", last_message->data);
from ulfius.
OK, that's weird but at least we found out where the problem is. There is no problem in the data itself, just when displaying it with a limit number of chars.
Can we consider this issue closed?
from ulfius.
Yes.
Thanks again for your support.
from ulfius.
Related Issues (20)
- [Issue] simple_example: build failed HOT 1
- ulfius_add_endpoint_by_val() url_prefix VS. url_format HOT 2
- HTTP GET with array as response body HOT 2
- simple_example as static build for managed server HOT 2
- undefined reference to `pointer_list_init' HOT 2
- How to setup https mode? HOT 4
- Sending file in response for Ulfius REST request
- Do we have any official Ulifius Yocto recipe? HOT 1
- How can I reopen a closed issue? HOT 4
- [Issue]../../src/libulfius.so: undefined reference to `[email protected]' HOT 1
- [Issue] A use after free bug in src/ulfius.c HOT 1
- [Issue]A double free bug in ulfius.c HOT 4
- [Issue]A use after free bug in src/ulfius.c HOT 1
- [Feature request] How to use libulfius to implement a secure, asynchronious and scalable REST API? HOT 3
- What is the best way to let libulfius interact with libpq? HOT 2
- uwsc can't connect to socket while wscat can HOT 2
- Ulfius failed to link microhttpd on mingw64 using CMake HOT 4
- Support for graceful shutdown HOT 2
- How to add swagger openAPI documentation for ulfius based webservices ? HOT 3
- Issue faced in file_upload_callback in Ulfius TLS mode [HTTPS] HOT 3
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 ulfius.