   }
 
   if (client.available()) {
-    String irCode = client.readStringUntil('\r');  // Exclusive of \r
+    String ir_code_str = client.readStringUntil('\r');  // Exclusive of \r
     client.readStringUntil('\n');  // Skip new line as well
     client.flush();
-    parseString(irCode);
+    sendGCString(ir_code_str);
   }
 }

/*
 * IRremoteESP8266: IRGCTCPServer - send Global Cache-formatted codes via TCP.
 * An IR emitter must be connected to GPIO pin 4.
 * Version 0.1 1 April, 2016
 * Copyright 2016 Hisham Khalifa, http://www.hishamkhalifa.com
 *
 * Example command - Samsung TV power toggle: 38000,1,1,170,170,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,63,20,63,20,63,20,63,20,63,20,63,20,1798\r\n
 */

#include <ESP8266WiFi.h>

#include <WiFiClient.h>
#include <WiFiServer.h>

const char* ssid = "...";  // Put your WIFI SSID here.
const char* password = "...";  // Put your WIFI password here.

WiFiServer server(4998);  // Uses port 4998.
WiFiClient client;

uint16_t *code_array;
IRsend irsend(4);  // an IR emitter led is connected to GPIO pin 4

void sendGCString(String str) {
  int16_t index;
  uint16_t count;

  // Find out how many items there are in the string.
  index = -1;
  count = 1;
  do {
    index = str.indexOf(',', index + 1);
    count++;
  } while (index != -1);

  // Now we know how many there are, allocate the memory to store them all.
  code_array = reinterpret_cast<uint16_t*>(malloc(count * sizeof(uint16_t)));
  // Check we malloc'ed successfully.
  if (code_array == NULL) {  // malloc failed, so give up.
    Serial.printf("\nCan't allocate %d bytes. (%d bytes free)\n",
                  count * sizeof(uint16_t), ESP.getFreeHeap());
    Serial.println("Giving up & forcing a reboot.");
    ESP.restart();  // Reboot.
    delay(500);  // Wait for the restart to happen.
    return;  // Should never get here, but just in case.
  }

  // Now convert the strings to integers and place them in code_array.
  count = 0;
  uint16_t start_from = 0;
  do {
    index = str.indexOf(',', start_from);
    code_array[count] = str.substring(start_from, index).toInt();
    start_from = index + 1;
    count++;
  } while (index != -1);

  irsend.sendGC(code_array, count);  // All done. Send it.
  free(code_array);  // Free up the memory allocated.
}

void setup() {
  // initialize serial:
  Serial.begin(115200);
  delay(100);
  Serial.println(" ");
  Serial.println("IR TCP Server");

