What I do with return strings like this is match them with a regular expression. Something like:
onData=function(a){
b=a.match(/(ISCP\x00\x00\x00\x10\x00\x00\x00\x08\x01\x00\x00\x00!)([\x00-\x7F])(.*)(\r)/);
System.print(b[2]);
};
You could even create expression for every case, but I'm not sure how well that works performance wise.
Also please note that you think that you're sending "ISCP\x00\x00\x00\x10\x00\x00\x00\x08\x01\x00\x00\x00" +"!1PWRQSTN\r" but what you're actually sending is: 49 53 43 50 00 00 00 10 00 00 00 08 01 00 00 00 21 31 50 57 52 51 53 54 4e 0d.
There is no such thing as ASCII in the TCP frame, all you're doing is trying to read as character codes or asking to send the character code. The socket send and onData methods will simply convert before sending or after receiving.
So to make life a little easier:
"ISCP\x00" = "\x49\x53\x43\x50\x00" = String.fromCharCode(73,83,67,80,0)
parseInt(0x49,16) = 73
a = "ISCP\x00"
a.charCodeAt(0) = 73
a.charCodeAt(1) = 83
a.charCodeAt(2) = 67
a.charCodeAt(3) = 80
a.charCodeAt(4) = 0
Last edited by sWORDs on November 2, 2010 20:02.