Esempio n. 1
0
        /// <summary>
        /// Sends an object to the network stream.
        /// </summary>
        /// <param name="messageToSend">The object to send to the network stream.</param>
        public async Task <bool> SendMessage(INetworkMessage messageToSend)
        {
            //Serialize object with TCPStandard
            byte[] buffer = TransferStandards.MessageToStandardSequence(messageToSend);

            try
            {
                //Send serialized object
                await networkStream.WriteAsync(buffer, 0, buffer.Length);
            }
            catch
            {
                Disable();
                return(false);
            }

            return(true);
        }
        public async Task <bool> SendMessage(INetworkMessage messageToSend)
        {
            //Convert to standard sequence
            byte[] buffer = TransferStandards.MessageToStandardSequence(messageToSend, sizeData: false, typeData: true);

            try
            {
                //Send serialized object
                await udpSender.SendAsync(buffer, buffer.Length);
            }
            catch
            {
                //Network error
                Disable();
                return(false);
            }

            return(true);
        }