예제 #1
0
        public async Task <bool> WriteAsync(string message)
        {
            try
            {
                uint   messageLength = (uint)message.Length;
                byte[] countBuffer   = BitConverter.GetBytes(messageLength);
                byte[] buffer        = Encoding.UTF8.GetBytes(message);

                await outStream.WriteAsync(countBuffer, 0, countBuffer.Length);

                await outStream.WriteAsync(buffer, 0, buffer.Length);

                return(true);
            }
            catch (System.IO.IOException)
            {
                return(false);
            }
            catch (Java.IO.IOException)
            {
                return(false);
            }
            catch (System.NullReferenceException)
            {
                return(false);
            }
        }
예제 #2
0
        public async Task SendMessage(string msg)
        {
            var message = msg;

            if (outStream != null)
            {
                uint   messageLength = (uint)message.Length;
                byte[] countBuffer   = BitConverter.GetBytes(messageLength);
                byte[] buffer        = Encoding.UTF8.GetBytes(message);

                await outStream.WriteAsync(countBuffer, 0, countBuffer.Length);

                await outStream.WriteAsync(buffer, 0, buffer.Length);

                await outStream.FlushAsync();
            }
        }