I receive a message from the server on the socket. The Receive method takes byte[] as a parameter, and since I do not know what size the message will be, I allocate memory with a margin of, for example, 100 bytes.
byte[] byteMessage = new byte[100]; socket.Receive(byteMessage); After receiving I convert to string using:
string strMessage = Encoding.Default.GetString(byteMessage); As a result, the string strMessage is a string that I need, but with a bunch of spaces at the end.
Questions:
- Can I get the size of the received message by socket?
- If not, how to determine the end of the received message?
Encoding.Default. BecauseEncoding.Defaultmeans ANSI-encoding on the client, which with great probability does not coincide with the encoding in which the server sends the data. - VladD