Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket server has big delay when sending messages #2780

Closed
xeonqq opened this issue May 30, 2024 · 3 comments · Fixed by #2782
Closed

Websocket server has big delay when sending messages #2780

xeonqq opened this issue May 30, 2024 · 3 comments · Fixed by #2782

Comments

@xeonqq
Copy link
Contributor

xeonqq commented May 30, 2024

Issue can reprodued in PR #2779
Problem is present on both esp8266 and esp32

simplescreenrecorder-2024-05-30_16.38.47.mp4

Problem can be seen in the video, in the serial terminal the messages are correctly sent in 4Hz by the timer started in the webserver here https://github.com/SmingHub/Sming/pull/2779/files#diff-5d28eaa0f4c730196fcd5810fce411e7d3ae309cd0815b15c6cd85bb9c8444d5R36

However on the receiving side the messages are not received in 4hz, shown in the web browser, 4 messages are recieved at the same time in 1Hz interval. Websocket client code here https://github.com/SmingHub/Sming/pull/2779/files#diff-4afbd2690aa9973b367ecf1c7b8645eacc30423c4ee0062b0740552a869196c1R41

This hinders real-time data analysis, since I want to plot roll pitch yaw in real time

@mikee47
Copy link
Contributor

mikee47 commented May 31, 2024

Try this patch:

diff --git a/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp b/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp
index e38363e4c..8e50ecd6d 100644
--- a/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp
+++ b/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp
@@ -294,7 +294,11 @@ bool WebsocketConnection::send(IDataSourceStream* source, ws_frame_type_t type,
 	}
 
 	// Pass stream to connection
-	return connection->send(sourceRef.release());
+	if(!connection->send(sourceRef.release())) {
+		return false;
+	}
+	connection->commit();
+	return true;
 }
 
 void WebsocketConnection::broadcast(const char* message, size_t length, ws_frame_type_t type)

@xeonqq
Copy link
Contributor Author

xeonqq commented May 31, 2024

Hi, Mikee,
Thanks a lot, I think the problem is solved with your patch.
Are you planning to merge it?

big delay solved with this patch shown in video below:

issue_solved.mp4

@mikee47
Copy link
Contributor

mikee47 commented May 31, 2024

Thanks a lot, I think the problem is solved with your patch.
Are you planning to merge it?

Great! PR en-route.

slaff pushed a commit that referenced this issue Jun 1, 2024
Fixes #2780 by kicking TCP when messages are queued. Without this messages are sent lazily by lwip stack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants