Have any friends studied WebSocket? Ask for advice.

using PHP as the background to deal with the client"s WebSocket connection, you need to use the socket_* function family. The function to receive the message is socket_recv, which requires a buffer variable and the maximum number of bytes. But before receiving the message, how do you know how big the message is from the client?

Whether

needs to develop its own protocol, for example, the data sent cannot exceed 4294967296 (4GB), so the first ten characters of each message represent the length of the message. In addition, just as HTTP with Cookie,WebSocket may also need each message with session ID to distinguish users. Are all these specified by server developers? If so, are there any established standards in the industry for reference? Or do you play it all by yourself?

thank you!

Jul.15,2022

swoole,workerman get to know

$data = '';
while (@socket_recv($my_socket, $res, 8192, 0))
{
    $data .= $res;
}
echo $data;

swoole is convenient, and workerman can be

.

take a look at workerman
https://github.com/walkor/web...

.

Connect with parameters such as uid to the server

ws://wd.xxx.com?uid=23

your question is a little confused

underlying socket function, no matter what application layer protocol you are, they just accept the byte flow. The application layer protocol is parsed by yourself. After you receive the byte flow, you do the application layer protocol parsing by yourself.

websocket has its own protocol (protocol header + payload+ check, etc.)
if a websocket protocol packet is too large, you need to receive it multiple times and then splice it

suppose your buffer is 1024 bytes, and a websocket packet is 1500 bytes.
then the first time you receive 1024 and find that the protocol packet cannot be fully parsed, put it in the cache. After taking the next 1024 bytes and cobbling up 1500 bytes, you will find that the protocol packet has been parsed successfully, and all that is left is the contents of the next packet

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf0923-31066.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf0923-31066.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?