Exemplo n.º 1
0
        /// <summary>
        /// Send the specified methodType and JSON to the TCP server.
        /// </summary>
        /// <param name="methodType">Method type.</param>
        /// <param name="json">JSON serialized Request.</param>
        /// <returns>JSON serialized Response</returns>
        public override async Task<string> SendAsync(Core.Connection.MethodType methodType, string json)
        {
            var client = new TcpClient();

            // decomment for debugging purpose

            /*try
            {
                client.Connect(
                    Core.Models.Cheats.DEBUG_TCP_SERVER,
                    Core.Models.Cheats.DEBUG_TCP_PORT);
            }
            catch (SocketException exception)*/
            {
                client.Connect(
                    Common.Constants.ClientConstants.TCP_SERVER,
                    Common.Constants.ClientConstants.TCP_PORT);                     
            }

            var stream = client.GetStream();

            var packetOut = new Core.Connection.Packet();
            packetOut.Content = json;
            packetOut.MethodType = methodType;
            await packetOut.SendAsync(stream);
            var packetIn = await Core.Connection.Packet.ReceiveAsync(stream);
           
            client.Close();
            return packetIn.Content;
        }
Exemplo n.º 2
0
        public async void SendAndRecive()
        {
            var testPackageOut = new Core.Connection.Packet();
            testPackageOut.Content = JsonConvert.SerializeObject("json");
            //"{\"Status\":0,\"Actions\":[[],[],[],[],[],[],[],[],[],[],[],[],[{\"Parameters\":{\"CreatePosition\":{\"X\":5316345,\"Y\":3354734},\"CreateBuilding\":276},\"Type\":2}],[],[],[],[],[],[],[],[],[],[],[],[]],\"Entities\":[]}"
            //what does Default ??
            testPackageOut.MethodType = Core.Connection.MethodType.Default;

            var client = new TcpClient();
            client.Connect(
                Client.Common.Constants.ClientConstants.TCP_SERVER,
                Client.Common.Constants.ClientConstants.TCP_PORT);

            var stream = client.GetStream();

            await testPackageOut.SendAsync(stream);

            var testPackageIn = await Core.Connection.Packet.ReceiveAsync(stream);

            Assert.AreEqual(testPackageOut.GetHashCode(), testPackageIn.GetHashCode());
        }