0

Why do I receive \0 in my data when receiving data from tcpipclient

I try to make a tcp-ip client server. I use this article https://www.developerfusion.com/article/3997/socket-programming-in-c-part-2/2/ When the client sends "Hello" The server reads H\0e\0l\0l\0o\0 Why ? Below the code of the onReceive public void OnDataReceived(IAsyncResult asyn) { //end receive... int iRx = 0 ; iRx = m_socClient.EndReceive (asyn); char[] chars = new char[iRx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(m_DataBuffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); WaitForData(); }

20th Nov 2018, 9:41 PM
sneeze
sneeze - avatar
1 Resposta
+ 4
sneeze Honestly I don't have a solution for this, but to my understanding, when a string consists of characters with null characters '\0' in between, it is a Unicode encoded string, also known as double byte, or wide char string. If you can, find a way to read and display the string correctly. I thought VS was Unicode compliant but in this case I don't know why, sorry : )
26th Nov 2018, 6:48 PM
Ipang