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

AsyncWebSocket disconnected by client after 100s #255

Closed
keduro opened this issue Oct 10, 2017 · 1 comment
Closed

AsyncWebSocket disconnected by client after 100s #255

keduro opened this issue Oct 10, 2017 · 1 comment

Comments

@keduro
Copy link

keduro commented Oct 10, 2017

This is my first post (so please take it easy on me); I would like to share an issue I've been having and how I resolved it. I have an ESP8266 running ESPAsyncWebServer which connects to a .net ClientWebSocket. Client connected just fine, websocket dialogue ensued, then after 100 seconds the client closed the connection. Google revealed the following similar issues .NET WebSockets forcibly closed despite keep-alive and activity on the connection and WebSocket Implementation Disconnects Every 100 Seconds

Critically If a "Content-Length: 0" header is included in the "101 Switching Protocols" response from a WebSocket server, WebSocketClient gets confused and schedules the connection for cleanup in 100 seconds. and According to RFC 7230 Section 3.3.2, Content-Length is prohibited in 1xx (Informational) messages. Using Wireshark I confirmed that the ESPAsyncWebServer was indeed including the "Content-Length: 0" header in the "101 Switching Protocols" response.

I have successfully resolved the issue by adding line

_sendContentLength = false;

after

_server = server;
_code = 101;

at the top of AsyncWebSocketResponse::AsyncWebSocketResponse in AsyncWebSocket.cpp.

Now the client happily remains connected to the server. 😃 😃 😃

Also want to say what a great library ESPAsyncWebServer is. Had been using ESP8266WebServer and not only was it slow but http: page requests to the server often resulted in corrupted websocket messages and exceptions being raised in the client. None of that now.

@me-no-dev
Copy link
Owner

Hahaha :D Thanks for the good find and the fact that you even took care of resolving it. Let me have a look and update :)

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

No branches or pull requests

2 participants