Home » U++ Library support » U++ Core » [SOLVED]Some modifications for WebSocket only as Client
[SOLVED]Some modifications for WebSocket only as Client [message #50325] |
Thu, 20 September 2018 13:50 |
kasome
Messages: 78 Registered: July 2008 Location: Taiwan
|
Member |
|
|
Hi, all
Here's some modifications for WebSocket, and I only test WebSocket as Client,and hope that helps.
In upp\uppsrc\Core\WebSocket.cpp
Modify
void WebSocket::SendRequest()
{
........................................
for(int i = 0; i < 20; i++)
h.Cat(Random());
........................................
}
to
void WebSocket::SendRequest()
{
........................................
for(int i = 0; i < 16; i++)
h.Cat(Random());
........................................
}
Because from https://tools.ietf.org/html/rfc6455
Quote:
The value of this header field MUST be a nonce consisting of a randomly selected 16-byte value that has been base64-encoded.
NOTE: As an example, if the randomly selected value was the sequence of bytes 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10, the value of the header field would be "AQIDBAUGBwgJCgsMDQ4PEC=="
============================================================ =====================================================
Modify
void WebSocket::Close(const String& msg, bool wait_reply)
{
........................................
SendRaw(CLOSE|FIN, msg);
........................................
}
void WebSocket::FrameData()
{
........................................
SendRaw(PONG|FIN, data);
........................................
}
to
void WebSocket::Close(const String& msg, bool wait_reply)
{
........................................
SendRaw(CLOSE|FIN, msg, MASK);
........................................
}
void WebSocket::FrameData()
{
........................................
SendRaw(PONG|FIN, data, MASK);
........................................
}
Because from https://tools.ietf.org/html/rfc6455
Quote:
A client MUST mask all frames that it sends to the server (Note that masking is done whether or not the WebSocket Protocol is running over TLS)
The server MUST close the connection upon receiving a frame that is not masked. In this case, a server MAY send a Close frame with a status code of 1002 (protocol error)
A server MUST NOT mask any frames that it sends to the client. A client MUST close a connection if it detects a masked frame.
[Updated on: Fri, 21 September 2018 10:52] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Fri Apr 26 05:27:21 CEST 2024
Total time taken to generate the page: 0.04742 seconds
|