Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I parse incoming data as to separate commands without running into trouble with payload commands?

0
Posted

How can I parse incoming data as to separate commands without running into trouble with payload commands?

0

We recommend implementing your program in a manner similar to the one below. • Whenever new data from the server arrives over the socket, append it to a string that will be used as a “cache”. Each time you receive data, call the cache parser function as well. • The cache parser function will examine the cache variable and look for a newline. • If one is not found, the function will return without doing anything. • If one is found, it will read everything from the beginning of the cache up to the newline and put it into a new variable. It will then remove the command up to (and including) the newline from the beginning of the cache. • The cache parser will look at the first three bytes of the command. • If the command is recognized as a regular command, it will call the handler for that command and loop back to see if there are more commands in the cache. • If the command is recognized as a payload command, it will look at the specified length of the payload, and compare that to the len

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123