///<summary> ///connect to server ///</summary> public void ConnectToMultiPlayerServer() { if (!internetConnection) { Debug.LogError("[GamingCloud] Internet Connection Not Reachable! Please Try Again Later"); return; } if (isConnected) { Debug.LogWarning("[GamingCloud] You are Connected To Server"); return; } if (gameObject.GetComponent <UnityMainThreadDispatcher>() == null) { gameObject.AddComponent(typeof(UnityMainThreadDispatcher)); } streamer = new tcpStreamer(BASE_URL, PORT, packetSize); streamer.OnPacketRecieve += listenData; streamer.OnConnected += () => { UnityMainThreadDispatcher.Instance().Enqueue(() => { this._isConnected = true; Dictionary <string, string> payload = GCPolicy.GetRequiredQueries(GCPolicy.QueryMode.TCP); string pid; if (this.testPlayerId.Length > 0) { pid = this.testPlayerId; } else if (!Players.IsLogin) { Debug.LogError("[GamingCloud] You are supposed to login to gamingcloud player account!"); return; } else { pid = Players.PlayerToken; } if (pid == null || pid.Trim().Length == 0) { Debug.LogError("[GamingCloud] You are supposed to login to gamingcloud player account!"); return; } payload.Add("PlayerId", pid); this.sendPacket("authentication", this._netId, JsonConvert.SerializeObject(payload)); }); }; }
// static string baseURL = "http://localhost:4000"; // static string baseURL = "http://172.16.73.123:4000"; static void SetHeader(HttpClient client) { foreach (KeyValuePair <string, string> item in GCPolicy.GetRequiredQueries(GCPolicy.QueryMode.HTTP)) { client.DefaultRequestHeaders.Add(item.Key, item.Value); } client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }