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

Many optimizations for the client side of the library #5

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

pablorodiz
Copy link

@pablorodiz pablorodiz commented Jun 9, 2016

  • Response payload reading during handshake causes data loss if server sends first mesage on the payload. Added header section end (empty line) detection to solve.
  • Added possibility to use transmit buffer on sendData.
  • Added connected() function to allow application to check status.
  • Added possibility to include other headers on the handshake (for authentication)
  • And some corrections for compilation on ESP8266 and reduce logging when not DEBUGGING

… of the handshake response. So I added headers end detection (empty line) and stop reading, so the remaining bytes of the packet will be considered part of the websocket communication
…nnection is correct before calling any blocking-data-read function
@pablorodiz pablorodiz changed the title Avoid data loss if server sends first mesage on the response payload Avoid data loss if server sends first mesage on the response payload, and speed up failure of sendData in case of disconnection Jun 14, 2016
@pablorodiz
Copy link
Author

pablorodiz commented Jun 14, 2016

Added one commit with sendEncodedData rewritten. With the original implementation it is very very slow to detect a disconnection. It takes as long as the time out of the socket multiplied by the number of bytes being sent, since all frames are send byte by byte. With my changes all the frame header is sent in only one write operation, and if it fails it does not try to send the payload, so only one timeout lapse is need to detect a connection failure.

…o user can completely avoid the use of Stings
@pablorodiz pablorodiz changed the title Avoid data loss if server sends first mesage on the response payload, and speed up failure of sendData in case of disconnection Many optimizations for the client side of the library Jun 20, 2016
@pablorodiz
Copy link
Author

Strings use heap memory, so if you use them a lot, as when periodically reading messages received through the websocket, the heap memory gets fragmented and the program gets in a not enough memory exception (or at least that happens to me on ESP8266 after some time). So I created a new implementation of the getData function to avoid using Strings, and using char arrays (created on the stack) instead.

…8266 where byte-by-byte sending is extremely slow. Be aware that if using buffered send "sendData" just stores messages in the buffer. To perform the actual send the program needs to call the new function "process" periodically in the main loop.
@pablorodiz
Copy link
Author

After finding a lot of problems, including system reboots, in the ESP8266 I decided to implement a new method for storing messages in a buffer before sending them. ESP8266 is very sensitive to small packets, since its transmit window is only 1.

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 this pull request may close these issues.

1 participant