Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 812207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:10:03+00:00 2026-05-15T01:10:03+00:00

I’m exploring MSMQ services, and I wrote a simple console client-server application that sends

  • 0

I’m exploring MSMQ services, and I wrote a simple console client-server application that sends each of the client’s keystrokes to the server. Whenever hit a control character (DEL, ESC, INS, etc) the server understandably throws an error. However, whenever I type a space character, the server receives the packet but doesn’t throw an error and doesn’t display the space.

Server:

namespace QIM
{
    class Program
    {
        const string QUEUE = @".\Private$\qim";
        static MessageQueue _mq;
        static readonly object _mqLock = new object();
        static XmlSerializer xs;

        static void Main(string[] args)
        {
            lock (_mqLock)
            {
                if (!MessageQueue.Exists(QUEUE))
                    _mq = MessageQueue.Create(QUEUE);
                else
                    _mq = new MessageQueue(QUEUE);
            }
            xs = new XmlSerializer(typeof(string));
            _mq.BeginReceive(new TimeSpan(0, 1, 0), new object(), OnReceive);
            while (Console.ReadKey().Key != ConsoleKey.Escape) { }
        }

        static void OnReceive(IAsyncResult result)
        {
            Message msg;
            lock (_mqLock)
            {
                try
                {
                    msg = _mq.EndReceive(result);
                    Console.Write(".");
                    Console.Write(xs.Deserialize(msg.BodyStream));
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                }
            }
            _mq.BeginReceive(new TimeSpan(0, 1, 0), new object(), OnReceive);
        }
    }
}

Client:

namespace QIM_Client
{
    class Program
    {
        const string QUEUE = @".\Private$\qim";
        static MessageQueue _mq;

        static void Main(string[] args)
        {
            if (!MessageQueue.Exists(QUEUE))
                _mq = MessageQueue.Create(QUEUE);
            else
                _mq = new MessageQueue(QUEUE);
            ConsoleKeyInfo key = new ConsoleKeyInfo();
            while (key.Key != ConsoleKey.Escape)
            {
                key = Console.ReadKey();
                _mq.Send(key.KeyChar.ToString());
            }
        }
    }
}

Client Input:

Testing, Testing…

Server Output:

.T.e.s.t.i.n.g.,..T.e.s.t.i.n.g……

You’ll notice that the space character sends a message, but the character isn’t displayed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:10:04+00:00Added an answer on May 15, 2026 at 1:10 am

    Your issue is not with MSMQ, it’s with the XmlSerializer class. See:

    var key = Console.ReadKey();
    
    XmlSerializer s = new XmlSerializer(typeof(string));
    
    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
    {
        s.Serialize(ms, key.KeyChar.ToString());
    
        ms.Position = 0;
    
        var foo = (string)s.Deserialize(ms);
    }
    

    If you type a space in the console, you’ll see that key.KeyChar.ToString() yields " ", but foo is equal to "". Because of the default implementation of XmlReader, the XmlSerializer class considers a string of only whitespace to be empty; if the string contains any other characters, both leading and trailing spaces are preserved. The whitespace does get serialized, but deserializing it turns it into an empty string.

    Use this instead:

    Console.Write(
        s.Deserialize(System.Xml.XmlReader.Create(msg.BodyStream, 
                                              new System.Xml.XmlReaderSettings() 
                                              { 
                                                  IgnoreWhitespace = false 
                                              })));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer concat( substring-before($s, '_'), substring-before(substring-after($s, '_'), '_') ) Alternatively: string-join(tokenize($s, '_')[position()… May 15, 2026 at 3:12 pm
  • Editorial Team
    Editorial Team added an answer anyone know how i can access email contents? The Email… May 15, 2026 at 3:12 pm
  • Editorial Team
    Editorial Team added an answer The temporary directory is missing. The uploaded file is first… May 15, 2026 at 3:12 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.