mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-07-15 00:06:30 +02:00
Update websocket client handshake
Sending handshake with only one tcp.write. Note: it solve connection problem with the QT websocket server.
This commit is contained in:
@ -272,33 +272,25 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
|
|||||||
|
|
||||||
unsigned long start = micros();
|
unsigned long start = micros();
|
||||||
|
|
||||||
//todo use tcp.write only once
|
String handshake;
|
||||||
|
handshake="GET "+client->cUrl+" HTTP/1.1\r\n";
|
||||||
|
handshake+="Host: "+_host+"\r\n";
|
||||||
|
handshake+="Upgrade: websocket\r\n";
|
||||||
|
handshake+="Connection: Upgrade\r\n";
|
||||||
|
handshake+="User-Agent: arduino-WebSocket-Client\r\n";
|
||||||
|
handshake+="Sec-WebSocket-Version: 13\r\n";
|
||||||
|
handshake+="Sec-WebSocket-Protocol: arduino\r\n";
|
||||||
|
handshake+="Sec-WebSocket-Key: "+client->cKey+"\r\n";
|
||||||
|
|
||||||
client->tcp.write("GET ");
|
if(client->cExtensions.length() > 0) {
|
||||||
client->tcp.write(client->cUrl.c_str(), client->cUrl.length());
|
handshake+="Sec-WebSocket-Extensions: "+client->cExtensions+"\r\n";
|
||||||
client->tcp.write(" HTTP/1.1\r\n"
|
|
||||||
"Host: ");
|
|
||||||
|
|
||||||
client->tcp.write(_host.c_str(), _host.length());
|
|
||||||
client->tcp.write("\r\n"
|
|
||||||
"Upgrade: websocket\r\n"
|
|
||||||
"Connection: Upgrade\r\n"
|
|
||||||
"User-Agent: arduino-WebSocket-Client\r\n"
|
|
||||||
"Sec-WebSocket-Version: 13\r\n"
|
|
||||||
"Sec-WebSocket-Protocol: arduino\r\n" // todo add api to set Protocol of Server
|
|
||||||
"Sec-WebSocket-Key: ");
|
|
||||||
|
|
||||||
client->tcp.write(client->cKey.c_str(), client->cKey.length());
|
|
||||||
client->tcp.write("\r\n");
|
|
||||||
|
|
||||||
if(client->cExtensions.length() > 0) {
|
|
||||||
client->tcp.write("Sec-WebSocket-Extensions: ");
|
|
||||||
client->tcp.write(client->cExtensions.c_str(), client->cExtensions.length());
|
|
||||||
client->tcp.write("\r\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header end wait for Server response
|
handshake+="\r\n";
|
||||||
client->tcp.write("\r\n");
|
client->tcp.write(handshake.c_str(), handshake.length());
|
||||||
|
|
||||||
|
DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header... Done (%uus).\n", (micros() - start));
|
||||||
|
|
||||||
|
|
||||||
DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header... Done (%uus).\n", (micros() - start));
|
DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header... Done (%uus).\n", (micros() - start));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user