Skip to main content
added 4 characters in body; Post Made Community Wiki
Source Link

here the problem is i am not recievingreceiving anything from server. My client disconnected from the server after sending the Upgrade headers. that's why in wiresharkwire-shark i am not getting anything from server I think so. here is code which do handshake with server:

here the problem is i am not recieving anything from server. My client disconnected from the server after sending the Upgrade headers. that's why in wireshark i am not getting anything from server I think so.

here.The problem is i am not receiving anything from server. My client disconnected from the server after sending the Upgrade headers. that's why in wire shark i am not getting anything from server I think so. here is code which do handshake with server: bool WebSocketClient::analyzeRequest() { String temp; int bite; bool foundupgrade = false; unsigned long intkey[2]; String serverKey; char keyStart[17]; char b64Key[25]; String key = "------------------------"; randomSeed(analogRead(0)); for (int i=0; i<16; ++i) { keyStart[i] = (char)random(1, 256); } base64_encode(b64Key, keyStart, 16); for (int i=0; i<24; ++i) { key[i] = b64Key[i]; } Serial.println(F("Sending websocket upgrade headers")); socket_client->print(F("GET ")); socket_client->print(path); socket_client->print(F(" HTTP/1.1\r\n")); socket_client->print(F("Upgrade: websocket\r\n")); socket_client->print(F("Connection: Upgrade\r\n")); socket_client->print(F("Host: ")); socket_client->print(host); socket_client->print(CRLF); socket_client->print(F("Sec-WebSocket-Key: ")); socket_client->print(key); socket_client->print(CRLF); socket_client->print(F("Sec-WebSocket-Protocol: ")); socket_client->print(protocol); socket_client->print(CRLF); socket_client->print(F("Sec-WebSocket-Version: 13\r\n")); socket_client->print(CRLF);

Serial.println(F("Analyzing response headers")); //here it got disconnected
while (socket_client->connected() && !socket_client->available()) { delay(100); Serial.println("Waiting..."); }

// TODO: More robust string extraction
while ((bite = socket_client->read()) != -1) {
    
    temp += (char)bite;
    if ((char)bite == '\n') {

#ifdef DEBUGGING Serial.print("Got Header: " + temp); #endif if (!foundupgrade && temp.startsWith("Upgrade: websocket")) { foundupgrade = true; } else if (temp.startsWith("Sec-WebSocket-Accept: ")) { serverKey = temp.substring(22,temp.length() - 2); // Don't save last CR+LF } temp = "";
}

    if (!socket_client->available()) {
      delay(20);
    }
}

key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
uint8_t *hash;
char result[21];
char b64Result[30];

Sha1.init();
Sha1.print(key);
hash = Sha1.result();

for (int i=0; i<20; ++i) {
    result[i] = (char)hash[i];
}
result[20] = '\0';

base64_encode(b64Result, result, 20);

// if the keys match, good to go
return serverKey.equals(String(b64Result));

}

bool WebSocketClient::analyzeRequest(){String temp;int bite;bool foundupgrade = false;unsigned long intkey[2];String serverKey;char keyStart[17];char b64Key[25];String key = "------------------------";randomSeed(analogRead(0));for(int i=0; iprint(F("GET "));socket_client->print(path);socket_client->print(F(" HTTP/1.1\r\n"));socket_client->print(F("Upgrade: websocket\r\n"));socket_client->print(F("Connection: Upgrade\r\n"));socket_client->print(F("Host: "));socket_client->print(host);socket_client->print(CRLF);socket_client->print(F("Sec-WebSocket-Key: "));socket_client->print(key);socket_client->print(CRLF);socket_client->print(F("Sec-WebSocket-Protocol: "));socket_client->print(protocol);socket_client->print(CRLF);socket_client->print(F("Sec-WebSocket-Version: 13\r\n"));socket_client->print(CRLF);Serial.println(F("Analyzing response headers"));//here it got disconnectedwhile(socket_client->connected() &&!socket_client->available()){delay(100);Serial.println("Waiting...");}// TODO: More robust string extractionwhile((bite = socket_client->read())!=-1){temp +=(char)bite;if((char)bite == '\n'){#ifdef DEBUGGINGSerial.print("Got Header: " + temp);#endifif(!foundupgrade && temp.startsWith("Upgrade: websocket")){foundupgrade = true;}else if(temp.startsWith("Sec-WebSocket-Accept: ")){serverKey = temp.substring(22,temp.length()- 2);// Don't save last CR+LF}temp = "";}if(!socket_client->available()){delay(20);}}key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";uint8_t *hash;char result[21];char b64Result[30];Sha1.init();Sha1.print(key);hash = Sha1.result();for(int i=0; i

here the problem is i am not recieving anything from server. My client disconnected from the server after sending the Upgrade headers. that's why in wireshark i am not getting anything from server I think so. here is code which do handshake with server:

here the problem is i am not recieving anything from server. My client disconnected from the server after sending the Upgrade headers. that's why in wireshark i am not getting anything from server I think so.

here is code which do handshake with server: bool WebSocketClient::analyzeRequest() { String temp; int bite; bool foundupgrade = false; unsigned long intkey[2]; String serverKey; char keyStart[17]; char b64Key[25]; String key = "------------------------"; randomSeed(analogRead(0)); for (int i=0; i<16; ++i) { keyStart[i] = (char)random(1, 256); } base64_encode(b64Key, keyStart, 16); for (int i=0; i<24; ++i) { key[i] = b64Key[i]; } Serial.println(F("Sending websocket upgrade headers")); socket_client->print(F("GET ")); socket_client->print(path); socket_client->print(F(" HTTP/1.1\r\n")); socket_client->print(F("Upgrade: websocket\r\n")); socket_client->print(F("Connection: Upgrade\r\n")); socket_client->print(F("Host: ")); socket_client->print(host); socket_client->print(CRLF); socket_client->print(F("Sec-WebSocket-Key: ")); socket_client->print(key); socket_client->print(CRLF); socket_client->print(F("Sec-WebSocket-Protocol: ")); socket_client->print(protocol); socket_client->print(CRLF); socket_client->print(F("Sec-WebSocket-Version: 13\r\n")); socket_client->print(CRLF);

Serial.println(F("Analyzing response headers")); //here it got disconnected
while (socket_client->connected() && !socket_client->available()) { delay(100); Serial.println("Waiting..."); }

// TODO: More robust string extraction
while ((bite = socket_client->read()) != -1) {
    
    temp += (char)bite;
    if ((char)bite == '\n') {

#ifdef DEBUGGING Serial.print("Got Header: " + temp); #endif if (!foundupgrade && temp.startsWith("Upgrade: websocket")) { foundupgrade = true; } else if (temp.startsWith("Sec-WebSocket-Accept: ")) { serverKey = temp.substring(22,temp.length() - 2); // Don't save last CR+LF } temp = "";
}

    if (!socket_client->available()) {
      delay(20);
    }
}

key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
uint8_t *hash;
char result[21];
char b64Result[30];

Sha1.init();
Sha1.print(key);
hash = Sha1.result();

for (int i=0; i<20; ++i) {
    result[i] = (char)hash[i];
}
result[20] = '\0';

base64_encode(b64Result, result, 20);

// if the keys match, good to go
return serverKey.equals(String(b64Result));

}

here the problem is i am not receiving anything from server. My client disconnected from the server after sending the Upgrade headers. that's why in wire-shark i am not getting anything from server I think so. here is code which do handshake with server.The problem is i am not receiving anything from server. My client disconnected from the server after sending the Upgrade headers. that's why in wire shark i am not getting anything from server I think so. here is code which do handshake with server:

bool WebSocketClient::analyzeRequest(){String temp;int bite;bool foundupgrade = false;unsigned long intkey[2];String serverKey;char keyStart[17];char b64Key[25];String key = "------------------------";randomSeed(analogRead(0));for(int i=0; iprint(F("GET "));socket_client->print(path);socket_client->print(F(" HTTP/1.1\r\n"));socket_client->print(F("Upgrade: websocket\r\n"));socket_client->print(F("Connection: Upgrade\r\n"));socket_client->print(F("Host: "));socket_client->print(host);socket_client->print(CRLF);socket_client->print(F("Sec-WebSocket-Key: "));socket_client->print(key);socket_client->print(CRLF);socket_client->print(F("Sec-WebSocket-Protocol: "));socket_client->print(protocol);socket_client->print(CRLF);socket_client->print(F("Sec-WebSocket-Version: 13\r\n"));socket_client->print(CRLF);Serial.println(F("Analyzing response headers"));//here it got disconnectedwhile(socket_client->connected() &&!socket_client->available()){delay(100);Serial.println("Waiting...");}// TODO: More robust string extractionwhile((bite = socket_client->read())!=-1){temp +=(char)bite;if((char)bite == '\n'){#ifdef DEBUGGINGSerial.print("Got Header: " + temp);#endifif(!foundupgrade && temp.startsWith("Upgrade: websocket")){foundupgrade = true;}else if(temp.startsWith("Sec-WebSocket-Accept: ")){serverKey = temp.substring(22,temp.length()- 2);// Don't save last CR+LF}temp = "";}if(!socket_client->available()){delay(20);}}key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";uint8_t *hash;char result[21];char b64Result[30];Sha1.init();Sha1.print(key);hash = Sha1.result();for(int i=0; i
Post Undeleted by Taher Kawantwala
Post Deleted by Taher Kawantwala
Source Link

here the problem is i am not recieving anything from server. My client disconnected from the server after sending the Upgrade headers. that's why in wireshark i am not getting anything from server I think so. here is code which do handshake with server:

here the problem is i am not recieving anything from server. My client disconnected from the server after sending the Upgrade headers. that's why in wireshark i am not getting anything from server I think so.

here is code which do handshake with server: bool WebSocketClient::analyzeRequest() { String temp; int bite; bool foundupgrade = false; unsigned long intkey[2]; String serverKey; char keyStart[17]; char b64Key[25]; String key = "------------------------"; randomSeed(analogRead(0)); for (int i=0; i<16; ++i) { keyStart[i] = (char)random(1, 256); } base64_encode(b64Key, keyStart, 16); for (int i=0; i<24; ++i) { key[i] = b64Key[i]; } Serial.println(F("Sending websocket upgrade headers")); socket_client->print(F("GET ")); socket_client->print(path); socket_client->print(F(" HTTP/1.1\r\n")); socket_client->print(F("Upgrade: websocket\r\n")); socket_client->print(F("Connection: Upgrade\r\n")); socket_client->print(F("Host: ")); socket_client->print(host); socket_client->print(CRLF); socket_client->print(F("Sec-WebSocket-Key: ")); socket_client->print(key); socket_client->print(CRLF); socket_client->print(F("Sec-WebSocket-Protocol: ")); socket_client->print(protocol); socket_client->print(CRLF); socket_client->print(F("Sec-WebSocket-Version: 13\r\n")); socket_client->print(CRLF);

Serial.println(F("Analyzing response headers")); //here it got disconnected
while (socket_client->connected() && !socket_client->available()) { delay(100); Serial.println("Waiting..."); }

// TODO: More robust string extraction
while ((bite = socket_client->read()) != -1) {
    
    temp += (char)bite;
    if ((char)bite == '\n') {

#ifdef DEBUGGING Serial.print("Got Header: " + temp); #endif if (!foundupgrade && temp.startsWith("Upgrade: websocket")) { foundupgrade = true; } else if (temp.startsWith("Sec-WebSocket-Accept: ")) { serverKey = temp.substring(22,temp.length() - 2); // Don't save last CR+LF } temp = "";
}

    if (!socket_client->available()) {
      delay(20);
    }
}

key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
uint8_t *hash;
char result[21];
char b64Result[30];

Sha1.init();
Sha1.print(key);
hash = Sha1.result();

for (int i=0; i<20; ++i) {
    result[i] = (char)hash[i];
}
result[20] = '\0';

base64_encode(b64Result, result, 20);

// if the keys match, good to go
return serverKey.equals(String(b64Result));

}