Beispiel #1
0
        private void DoClient(TcpClient socket)
        {
            using (NetworkStream stream = socket.GetStream())
                using (StreamReader fromClient = new StreamReader(stream))
                {
                    string strFromClient = fromClient.ReadLine();
                    Console.WriteLine($"From Client text : {strFromClient}");

                    BoxCalVol vol = JsonConvert.DeserializeObject <BoxCalVol>(strFromClient);
                    Console.WriteLine($"From Client as box volume : {vol}");

                    BoxCalLength length = JsonConvert.DeserializeObject <BoxCalLength>(strFromClient);
                    Console.WriteLine($"From Client as box length: {length}");
                }
        }
Beispiel #2
0
        public void StartClient()
        {
            BoxCalVol vol = new BoxCalVol(2, 2, 2);

            BoxCalLength length = new BoxCalLength(8, 2, 2);

            using (TcpClient cSocket = new TcpClient("localhost", port))
                using (Stream stream = cSocket.GetStream())
                    using (StreamWriter toServer = new StreamWriter(stream))
                    {
                        string jsonStr = JsonConvert.SerializeObject(vol);
                        Console.WriteLine($"Client json string: {jsonStr} and size:: {jsonStr.Length}");

                        toServer.WriteLine(jsonStr);

                        string jsonStr2 = JsonConvert.SerializeObject(length);
                        Console.WriteLine($"Client json string: {jsonStr2} and size:: {jsonStr2.Length}");

                        toServer.WriteLine(jsonStr);
                        toServer.WriteLine(jsonStr2);

                        toServer.Flush();
                    }
        }