예제 #1
0
        static void Main(string[] args)
        {
            var path = @"C:\Users\45535\Desktop\RAWDATA\C#\Projects\Assignment_3_Vers01\Client\Test.json";

            // Define and start TCP client
            using var tcpClient = new TcpClient();

            // Client connect to local via. port 5000.
            tcpClient.Connect(IPAddress.Loopback, 5000);
            Console.WriteLine("Client started");


            //Define our request
            Request request = new Request("update", path, 2, "Bent");

            //Send request to server - see Util.cs
            Util.SendRequest(tcpClient, request.ToJson());

            //Console.WriteLine($"Message to the server: {}");
            Console.WriteLine("We send this to the client: \n " + request.ToJson());
            //File.WriteAllText(path, request.ToJson());


            //Read responses from the server.
            string            r3 = ClientReadResponse(tcpClient, tcpClient.GetStream());
            ResponseContainer responseContainer = JsonConvert.DeserializeObject <ResponseContainer>(r3);


            Console.WriteLine($"The server responds:  \n + {responseContainer.Status} \n {responseContainer.Reason}");

            //We send respond to a JSON formatted string.


            //Now we desirialize it, so it will be stored in our "responseContainer.cs" OBS WAIT UNTIL WE SEND right response from server.
        }
예제 #2
0
        static void Main(string[] args)
        {
            string path = @"C:\Users\Jesper\Desktop\RAWDATA\C#\Projects\Assignment_3_Vers01\ClassLibrary1\JsonFiles\Test.json";

            // Define and start TCP client
            using var tcpClient = new TcpClient();

            // Client connect to local via. port 5000.
            tcpClient.Connect(IPAddress.Loopback, 5000);


            // "sWriter" = how we write to server.
            var sWriter = new BinaryWriter(tcpClient.GetStream(), Encoding.UTF8);

            // "sReader" = how we read responses
            var sReader = new StreamReader(tcpClient.GetStream(), Encoding.UTF8);

            //Define our request
            Request request = new Request("update", "/bla", 1, "Ole");

            //Send request to server - see Util.cs

            Util.SendRequest(tcpClient, request.ToJson());

            //Console.WriteLine($"Message from the server: {}");

            Console.Write(request.ToJson());
        }