Quote:
Can you give me any clue why it's not working for the 2nd message?
look where you have 'total' defined .. do you reset the value of total before you get the checksum for your second message ?
I would break out this code, to get the checksum
message = message.Replace('|', '\u0001');
byte[] messageBytes = Encoding.ASCII.GetBytes(message);
for (int i = 0; i < message.Length; i++)
total += messageBytes[i];
int checksum = 0;
foreach (byte chData in messageBytes)
{
checksum += chData;
}
checksum = total % 256;
string checksumStr = checksum.ToString().PadLeft(3, '0');
into a separate function/procedure/method - you repeat the code, real bad idea - if you break that code out of each location you can then go
checksumStr = getChecksum(message);
for example .. then you can remove this disaster
Quote:
public static int total;
from your client
While I'm here, I'll throw in my 2 cents worth on building messages like that by concatenating strings - its barely ok for a test - I'd expect someone working for me to make a message builder class, for each type of message (so it starts as an abstract class), that you pass the values to it and it builds the message nicely - your messages as they are are hard to extend, debug etc - I guess you're lucky you're not working for me :)