Ratchet
Ratchet copied to clipboard
How to frame multiple 'messages'?
I'm trying to replace a very old react PHP based server to a ratchet one based on PHP 8.
Most scenarios are working as intended, however I'm having difficulties with the following scenario;
- Client makes connection
- Server responds
- Client sends a message
- Server sends multiple messages
In this particular scenario (where there would be multiple messages being sent from ratchet server) the client would hang to whatever the value of the \stream_set_timeout() was set to, but then ending up receiving the same data anyways, causing tremendous amount of exec time differences between the two solution.
Unfortunately I'm unable to change the client right now, but the older react PHP based solution worked just fine. Looking at a higher level, everything should behave in a similar way, so I've decided to capture the traffic via tcpdump.
I've noticed based on the hex output of the followed TCP stream that wireshark seems to display the end of the previous message padded as follows:
20 30 0a 49 64 6c 65 2d 43 50 55 3a 20 39 37 0a 0.Idle- CPU: 97.
0a .
43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 Content- Length:
And the ratchet version is:
6c 65 2d 43 50 55 3a 20 39 37 0a 0a 43 6f 6e 74 le-CPU: 97..Cont
65 6e 74 2d 4c 65 6e 67 74 68 3a 20 39 32 30 0a ent-Leng th: 920.
I'm not familiar with how TCP works on a lower level, but I'd expect that this is perhaps because the first message is framed (possibly with 0xFD) and the ratchet version is not?
Right now I'm only iterating through an array of strings, and sending each message separately via: $from->send($message)
How would you go about reproducing the old traffic?
How would you go about reproducing the old traffic?
Not sure, read your message a few times but it's missing a few essential details. Like, were you using websockets before? What is the client? Why does it matter that the TCP messages don't change? (TCP will chop what ever data you want to sent in chunks of multiple messages when needed. But that shouldn't be an issue.) A gist demonstrating the changes would be welcome