Compare commits

..

3 Commits
1.0 ... 1.1

Author SHA1 Message Date
187a4ac823 bump version
optimize String usage (less malloc / realloc)
remove double debug line
2015-10-21 17:17:09 +02:00
d2d06b59a4 Merge pull request #13 from jc19000/master
Update websocket client handshake
2015-10-21 17:10:06 +02:00
b60599dcd7 Update websocket client handshake
Sending handshake with only one tcp.write.

Note: it solve connection problem with the QT websocket server.
2015-10-20 22:05:08 +02:00
2 changed files with 13 additions and 24 deletions

View File

@ -1,5 +1,5 @@
name=WebSockets
version=1.0
version=1.1
author=Markus Sattler
maintainer=Markus Sattler
sentence=WebSockets for Arduino (Server + Client)

View File

@ -272,33 +272,22 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
unsigned long start = micros();
//todo use tcp.write only once
client->tcp.write("GET ");
client->tcp.write(client->cUrl.c_str(), client->cUrl.length());
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");
String handshake = "GET " + client->cUrl + " HTTP/1.1\r\n"
"Host: " + _host + "\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"
"Sec-WebSocket-Key: " + client->cKey + "\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");
handshake += "Sec-WebSocket-Extensions: " + client->cExtensions + "\r\n";
}
// Header end wait for Server response
client->tcp.write("\r\n");
handshake += "\r\n";
client->tcp.write(handshake.c_str(), handshake.length());
DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header... Done (%uus).\n", (micros() - start));