title: Arduino does not support messages larger than 65535 characters using websocket protocol?
body: <p>I'm using the following <a href="https://github.com/brandenhall/Arduino-Websocket" rel="nofollow">Arduino websocket library</a>, I had a problem when trying to send messages over than 65535 characters, I got handshake fail error.<br>
  As long as the message doesn't exceeds this length, it worked perfectly  </p>
  
  <p>There's a note on the main web page of the library that states:  </p>
  
  <pre><code>Because of limitations of the current Arduino platform (Uno at the time of this writing),   
   this library does not support messages larger than 65535 characters.   
   In addition, this library only supports single-frame text frames.   
   It currently does not recognize continuation frames, binary frames, or ping/pong frames.
  </code></pre>
  
  <p>In the client header file named <strong>WebSocketClient.h</strong> there's the following comment:  </p>
  
  <pre><code>// Don't allow the client to send big frames of data. This will flood the arduino memory and might even crash it.  
      #ifndef MAX_FRAME_LENGTH
      #define MAX_FRAME_LENGTH 256
      #endif  
  </code></pre>
  
  <p>I'm using this old library because it is the only one worked for me on my <a href="http://arduino.cc/en/Main/ArduinoWiFiShield" rel="nofollow">Arduino WIFI shield</a>, I couldn't find other libraries that support WiFi shield since most of the webscket libraries are written for <a href="http://arduino.cc/en/Main/ArduinoEthernetShield" rel="nofollow">Arduino Eathernet Shield</a> support, which I don't have.  </p>
  
  <p><strong>My Arduino Code is</strong>  </p>
  
  <pre><code>/*DS18 Libs*/
  #include &lt;dht.h&gt;
  #include &lt;OneWire.h&gt;
  #include &lt;DallasTemperature.h&gt;
  /*Websocket Libs*/
  #include &lt;WebSocketServer.h&gt;
  #include &lt;WebSocketClient.h&gt;
  #include &lt;sha1.h&gt;
  #include &lt;MD5.h&gt;
  #include &lt;global.h&gt;
  #include &lt;Base64.h&gt;
  #include &lt;SPI.h&gt;
  #include &lt;WiFiUdp.h&gt;
  #include &lt;WiFiServer.h&gt;
  #include &lt;WiFiClient.h&gt;
  #include &lt;WiFi.h&gt;
  #include &lt;string.h&gt;
  
  char ssid[] = "AMM";
  char pass[] = "027274792";
  int status = WL_IDLE_STATUS;
  IPAddress server(192, 168, 1, 3);
  WiFiClient WiFiclient;
  WebSocketClient WSclient;
  
  // Data wire is plugged into port 2 on the Arduino
  #define ONE_WIRE_BUS 2
  // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)  
  
  OneWire oneWire(ONE_WIRE_BUS);
  // Pass our oneWire reference to Dallas Temperature. 
  DallasTemperature sensors(&amp;oneWire);
  
  //Humidture
  dht DHT;
  #define DHT11_PIN 4
  
  void setup()
  {
     Serial.begin(9600);
      while (!Serial) {
            ; // wait for serial port to connect. Needed for Leonardo only
  }
  
   //check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
      Serial.println("WiFi shield not present");
      // don't continue:
      while (true);
  }
  
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
      Serial.print("Attempting to connect to WPA SSID: ");
      Serial.println(ssid);
      // Connect to WPA/WPA2 network:    
      status = WiFi.begin(ssid, pass);
  }
  
  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  
  /* Connect to the websocket server*/
  if (WiFiclient.connect(server, 8080)) {
      Serial.println("Connected");
  }
  else {
      Serial.println("Connection failed.");
      while (1) {
          // Hang on failure
      }
  }
  
  // Handshake with the server
  WSclient.path = "/MyServer/endpoint/testtest/device/d6220ae7-caa9-48b5-92db-630c4c296ec4";
  WSclient.host = "192.168.1.3:8080";
  
  if (WSclient.handshake(WiFiclient)) {
      Serial.println("Handshake successful");
  }
  else {
      Serial.println("Handshake failed.");
      while (1) {
          // Hang on failure
      }
  }
  
  /*DS18*/
  sensors.begin();
   }
  
  void loop()
  {   
       WSclient.sendData("{\"service_code\":\"89c4da72-a561-47db-bf62-8e63f8c4bbf0\",\"data\":[" + getHumidtureValue() + "],\"service_type\":\"TemperatureHumidityAnalysis\"}");
       WSclient.sendData("{\"service_code\":\"bdc0f984-6550-4712-881f-b09071da5a73\",\"data\":" + getCBodyTempretureValue() + ",\"service_type\":\"TemperatureGaugeMonitor\"}");
       //line-3 commented WSclient.sendData("{\"service_code\":\"8c212432-a86e-4c18-a956-9dc0dbb648d4\",\"data\":[" + getHumidtureValue() + "],\"service_type\":\"HumidityGaugeMonitor\"}");
  }
  
   String getCBodyTempretureValue()
   {
       sensors.requestTemperatures(); // Send the command to get temperatures
       char charVal[10];
       return dtostrf(sensors.getTempCByIndex(0), 4, 2, charVal);
   }
  
   String getHumidtureValue()
   {
        String str = "";
        for (int i = 0; i &lt; 2; i++)
        {
           int chk = DHT.read11(DHT11_PIN);
           switch (chk)
           {
              case DHTLIB_OK:
                 Serial.println("OK,\t");
                 break;
              case DHTLIB_ERROR_CHECKSUM:
                 Serial.println("Checksum error,\t");
                 break;
              case DHTLIB_ERROR_TIMEOUT:
                 Serial.println("Time out error,\t");
                 break;
               default:
                 Serial.println("Unknown error,\t");
                 break;
             }
  
             char charVal[10];
             double tempF = (DHT.temperature * 9) / 5 + 32;
             str = dtostrf(tempF, 3, 1, charVal);
             str = str + "," + dtostrf(DHT.humidity, 3, 1, charVal);
             Serial.println(str);
             delay(200);
       }
       return str;
  
     }
  </code></pre>
  
  <p>The code above works perfectly, when I uncomment the third send statement in the loop function, I got the handshake failed error.  </p>
  
  <p>-Is it safe to modify the value of <strong>MAX_FRAME_LENGTH</strong> for the new versions of Arduino board, considering this library is an old one?<br>
  -Is there any other libraries better than this one that can support websocket on WiFi shield?  </p>
  
  <p>Any solution or idea will appreciated. </p>
  
  <p>Thanks in advance.</p>