Esempio n. 1
0
        public byte[] SendMessageFromClientToServer(string message)
        {
            var messageBytes    = Encoding.ASCII.GetBytes(message);
            var parser          = new UDPdgramDataParser();
            var messageChunk    = parser.GetDataChunks(messageBytes, "message")[0];
            var serializedChunk = messageChunk.Serialize();
            var encoded         = Encoding.ASCII.GetBytes(serializedChunk);

            socket.SendTo(encoded, sendingEp);
            return(listener.Receive(ref receivingEp));
        }
Esempio n. 2
0
        private bool SendFile(byte[] fileBytes)
        {
            var  parser     = new UDPdgramDataParser();
            var  fileChunks = parser.GetDataChunks(fileBytes, "file");
            bool totalSend  = false;
            int  counter    = 0;

            while (!totalSend)
            {
                if (SendFileChunk(fileChunks[counter]))
                {
                    counter++;
                    totalSend = counter == fileChunks.Count;
                    Console.WriteLine($"{counter} of {fileChunks.Count}");
                }
            }
            return(true);
        }