Code Monkey home page Code Monkey logo

Comments (15)

babelouest avatar babelouest commented on May 17, 2024

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.

mmardinian avatar mmardinian commented on May 17, 2024

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.

babelouest avatar babelouest commented on May 17, 2024

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.

mmardinian avatar mmardinian commented on May 17, 2024

Yes, that's what I did.
Actually more dirty: while(1) {...

from ulfius.

babelouest avatar babelouest commented on May 17, 2024

can you post your updated websocket_manager_callback? I'll try to reproduce your bug.

from ulfius.

mmardinian avatar mmardinian commented on May 17, 2024

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 thewebsocket_manager_callback? Should it be in the websocket_incoming_message_callback`?

from ulfius.

babelouest avatar babelouest commented on May 17, 2024

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.

babelouest avatar babelouest commented on May 17, 2024

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.

babelouest avatar babelouest commented on May 17, 2024

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.

mmardinian avatar mmardinian commented on May 17, 2024

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....

ulfius_websocket_incomingmessageissue

from ulfius.

mmardinian avatar mmardinian commented on May 17, 2024

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.

babelouest avatar babelouest commented on May 17, 2024

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.

mmardinian avatar mmardinian commented on May 17, 2024

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.

babelouest avatar babelouest commented on May 17, 2024

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.

mmardinian avatar mmardinian commented on May 17, 2024

Yes.
Thanks again for your support.

from ulfius.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.