I am trying to send a null char (0x00) at the end of my string. like adding “\0” to the end. Using WireShark i can see that it is not doing this.
I have tried these two way to do this, but neither are working, any suggestions ?
const string policy = "secure=\"false\"/>\0";
byte[] reply = Encoding.UTF8.GetBytes(policy);
m_clientSocket.Send(reply);
i then tried this, though i would increase the buffer size by one.
byte[] reply = new byte[policy.Length + 1];
reply = Encoding.UTF8.GetBytes(policy);
m_clientSocket.Send(reply);
This works, but i know its not doing it the correct way.
byte[] reply = new byte[policy.Length];
reply = Encoding.UTF8.GetBytes(policy);
m_clientSocket.Send(reply, reply.Length, SocketFlags.None);
byte[] t = new byte[1];
t[0] = 0;
m_clientSocket.Send(t, 1, SocketFlags.None);
I have also tried this, but then i get a exception when it runs.
byte[] reply = new byte[policy.Length + 1];
reply = Encoding.UTF8.GetBytes(policy);
m_clientSocket.Send(reply, reply.Length + 1, SocketFlags.None);
WouterH
September 23, 2011, 11:41am
3
Can you do it like this?
const string policy = "secure=\"false\"/>0";
byte[] reply = Encoding.UTF8.GetBytes(policy);
reply[reply.Length - 1] = 0; // Overwrite last character '0' with '\0'
m_clientSocket.Send(reply);
that worked, thanks.
I was reading here: http://msdn.microsoft.com/en-us/library/ms228362.aspx about the /0
where it says
so out of curiosity, is there a bug somewhere why when i add it in my string it is not working right ?
WouterH
September 23, 2011, 1:57pm
5
I full .NET a string can indeed contain \0 characters. But the implementation of NETMF is slightly different, where \0 means a terminator.
jasdev
September 24, 2011, 12:18am
6
Yes, I encountered this when working on a recent project. I was suprised to learn that NETMF does not support null characters in strings, especially since they seem to support unicode characters.
Here is a link I found about this subject: [url]http://netmf.codeplex.com/workitem/945[/url]
It is weird that some things i have finding out that .net seems to have .netmf does not. Early on i was told they are trying to save space. however not having the ability to us /0 is just absurd.