code: public void handleReceiverError()
  	{
  		try {
  			if (connected) {
  				close(true);
  			}
  		} catch (WebSocketException wse) {
              if (Log.isLoggable(TAG, DEBUG))
                  Log.d(TAG, "Exception closing web socket", wse);
  		}
  	}
docs: /*private synchronized void sendFrame(byte opcode, boolean masking, byte[] data) throws WebSocketException, IOException
  {
  int headerLength = 2; // This is just an assumed headerLength, as we use a ByteArrayOutputStream
  if (masking) {
  headerLength += 4;
  }
  ByteArrayOutputStream frame = new ByteArrayOutputStream(data.length + headerLength);
  
  byte fin = (byte) 0x80;
  byte startByte = (byte) (fin | opcode);
  frame.write(startByte);
  int length = data.length;
  int length_field = 0;
  
  if (length < 126) {
  if (masking) {
  length = 0x80 | length;
  }
  frame.write((byte) length);
  } else if (length <= 65535) {
  length_field = 126;
  if (masking) {
  length_field = 0x80 | length_field;
  }
  frame.write((byte) length_field);
  byte[] lengthBytes = intToByteArray(length);
  frame.write(lengthBytes[2]);
  frame.write(lengthBytes[3]);
  } else {
  length_field = 127;
  if (masking) {
  length_field = 0x80 | length_field;
  }
  frame.write((byte) length_field);
  Since an integer occupies just 4 bytes we fill the 4 leading length bytes with zero
  frame.write(new byte[]{0x0, 0x0, 0x0, 0x0});
  frame.write(intToByteArray(length));
  }
  
  byte[] mask = null;
  if (masking) {
  mask = generateMask();
  frame.write(mask);
  
  for (int i = 0; i < data.length; i++) {
  data[i] ^= mask[i % 4];
  }
  }
  
  frame.write(data);
  output.write(frame.toByteArray());
  output.flush();
  }