private void QueueRequest(string jsonRequestData, S2SCallback callback)
    {
#if DOT_NET
        //create new request
        HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(ServerURL);

        //customize request
        httpRequest.Method = "POST";
        httpRequest.ContentType = "application/json; charset=utf-8";
#endif
#if USE_WEB_REQUEST
        
        //create new request
        UnityWebRequest httpRequest = UnityWebRequest.Post(ServerURL, new Dictionary<string, string>());

        //customize request
        httpRequest.SetRequestHeader("Content-Type", "application/json; charset=utf-8");
#endif
        //store request info
        S2SRequest req = new S2SRequest();
        req.request = httpRequest;
        req.requestData = jsonRequestData;
        req.callback = callback;

        //add to requestqueue
        _requestQueue.Add(req);

        SendData(req.request, req.requestData);
    }
 public void Authenticate(S2SCallback callback)
 {
     _state = State.Authenticating;
     string jsonAuthString = "{\"service\":\"authenticationV2\",\"operation\":\"AUTHENTICATE\",\"data\":{\"appId\":\"" + AppId + "\",\"serverName\":\"" + ServerName + "\",\"serverSecret\":\"" + ServerSecret + "\"}}";
     _packetId = 0;
     QueueRequest(jsonAuthString, callback + OnAuthenticationCallback); //We need to call OnAuthenticate callback to refill the queue with requests waiting on an auth request, and handle heartbeat and sessionId data. 
 }
 public void SendHeartbeat(S2SCallback callback)
 {
     if (SessionId != null)
     {
         string jsonHeartbeatString = "{\"service\":\"heartbeat\",\"operation\":\"HEARTBEAT\"}";
         QueueRequest(jsonHeartbeatString, callback);
     }
 }
    /**
    * Send an S2S request.
    *
    * @param json S2S operation to be sent as a string
    * @param callback Callback function
    */
    public void Request(string jsonRequestData, S2SCallback callback)
    {
        if (_autoAuth == true)
        {
            if (!(_state == State.Authenticated) && _packetId == 0) //this is an authentication request no matter what
            {
                Authenticate(OnAuthenticationCallback);
            }
        }
        if (!(_state == State.Authenticated)) // these are the requests that have been made that are awaiting authentication. We NEED to store the request so we can properly call this function back for additional requests that are made after authenitcation.
        {
            S2SRequest nonAuthRequest = new S2SRequest();
            nonAuthRequest.requestData = jsonRequestData;
            nonAuthRequest.callback = callback;

            _waitingForAuthRequestQueue.Add(nonAuthRequest);
        }
        else
        {
            QueueRequest(jsonRequestData, callback);
        }
    }