// Path: sdk/src/main/java/com/theeyetribe/clientsdk/response/CalibrationPointEndResponse.java
// public class CalibrationPointEndResponse extends Response
// {
//     public static class Values
//     {
//         @SerializedName(Protocol.CALIBRATION_CALIBRESULT)
//         public CalibrationResult calibrationResult;
//     }
// 
//     public Values values = new Values();
// }
// 
// Path: sdk/src/main/java/com/theeyetribe/clientsdk/response/Response.java
// public class Response
// {
//     public String category;
//     public String request;
//     public int id;
//     public int statuscode;
// 
//     public transient long transitTime;
// }
// 
// Path: sdk/src/main/java/com/theeyetribe/clientsdk/response/ResponseFailed.java
// public class ResponseFailed extends Response
// {
//     public static class Values
//     {
//         @SerializedName(Protocol.KEY_STATUSMESSAGE)
//         public String statusMessage;
//     }
// 
//     public Values values = new Values();
// }


import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.theeyetribe.clientsdk.request.*;
import com.theeyetribe.clientsdk.response.CalibrationPointEndResponse;
import com.theeyetribe.clientsdk.response.Response;
import com.theeyetribe.clientsdk.response.ResponseFailed;
import com.theeyetribe.clientsdk.response.TrackerGetResponse;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.Enumeration;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
                InputStreamReader isr = new InputStreamReader(is, "UTF-8");
                reader = new BufferedReader(isr);

                while (!Thread.interrupted())
                {
                    while ((responseJson = reader.readLine()) != null)
                    {
                        if (!responseJson.isEmpty() && null != mResponseListener)
                        {
                            if(GazeManager.IS_DEBUG_MODE)
                                System.out.println("IN: " + responseJson);

                            jo = (JsonObject) jsonParser.parse(responseJson);
                            int id = null != jo.get(Protocol.KEY_ID) ? jo.get(Protocol.KEY_ID).getAsInt() : 0;
                            request = mOngoingRequests.containsKey(id) ? mOngoingRequests.remove(id) : null;

                            if (jo.get(Protocol.KEY_STATUSCODE).getAsInt() == HttpURLConnection.HTTP_OK)
                            {
                                if(request != null)
                                {
                                    //matching request handles parsing
                                    response = (Response) request.parseJsonResponse(jo, mGson);
                                    response.transitTime = System.currentTimeMillis() - request.timeStamp;
                                }
                                else
                                {
                                    // Incoming message has no id and is a reponse to a process or a pushed gaze data frame
                                    if (jo.get(Protocol.KEY_CATEGORY).getAsString().equals(Protocol.CATEGORY_CALIBRATION))
                                    {
                                        // response is calibration result
// Path: sdk/src/main/java/com/theeyetribe/clientsdk/response/CalibrationPointEndResponse.java
// public class CalibrationPointEndResponse extends Response
// {
//     public static class Values
//     {
//         @SerializedName(Protocol.CALIBRATION_CALIBRESULT)
//         public CalibrationResult calibrationResult;
//     }
// 
//     public Values values = new Values();
// }
// 
// Path: sdk/src/main/java/com/theeyetribe/clientsdk/response/Response.java
// public class Response
// {
//     public String category;
//     public String request;
//     public int id;
//     public int statuscode;
// 
//     public transient long transitTime;
// }
// 
// Path: sdk/src/main/java/com/theeyetribe/clientsdk/response/ResponseFailed.java
// public class ResponseFailed extends Response
// {
//     public static class Values
//     {
//         @SerializedName(Protocol.KEY_STATUSMESSAGE)
//         public String statusMessage;
//     }
// 
//     public Values values = new Values();
// }


// Path: sdk/src/main/java/com/theeyetribe/clientsdk/GazeApiManager.java
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.theeyetribe.clientsdk.request.*;
import com.theeyetribe.clientsdk.response.CalibrationPointEndResponse;
import com.theeyetribe.clientsdk.response.Response;
import com.theeyetribe.clientsdk.response.ResponseFailed;
import com.theeyetribe.clientsdk.response.TrackerGetResponse;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.Enumeration;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

                InputStreamReader isr = new InputStreamReader(is, "UTF-8");
                reader = new BufferedReader(isr);

                while (!Thread.interrupted())
                {
                    while ((responseJson = reader.readLine()) != null)
                    {
                        if (!responseJson.isEmpty() && null != mResponseListener)
                        {
                            if(GazeManager.IS_DEBUG_MODE)
                                System.out.println("IN: " + responseJson);

                            jo = (JsonObject) jsonParser.parse(responseJson);
                            int id = null != jo.get(Protocol.KEY_ID) ? jo.get(Protocol.KEY_ID).getAsInt() : 0;
                            request = mOngoingRequests.containsKey(id) ? mOngoingRequests.remove(id) : null;

                            if (jo.get(Protocol.KEY_STATUSCODE).getAsInt() == HttpURLConnection.HTTP_OK)
                            {
                                if(request != null)
                                {
                                    //matching request handles parsing
                                    response = (Response) request.parseJsonResponse(jo, mGson);
                                    response.transitTime = System.currentTimeMillis() - request.timeStamp;
                                }
                                else
                                {
                                    // Incoming message has no id and is a reponse to a process or a pushed gaze data frame
                                    if (jo.get(Protocol.KEY_CATEGORY).getAsString().equals(Protocol.CATEGORY_CALIBRATION))
                                    {
                                        // response is calibration result
                                        response = mGson.fromJson(jo, CalibrationPointEndResponse.class);