I’ve actually been working on this for the past few hours… I’ve overcome the encoding and decoding of the messages.
However, I now face a difference problem. I can issue commands, however, the responses to each command are truncated to that of the length of the received string…
EXPECTED chat result: Oh dear, I’m 152
RECEIVED chat result: Oh
DEBUGGING FROM SERVER:
2011-11-23 23:22:14 System: Socket Resource id #7 created. 2011-11-23 23:22:14 System: Socket bound to 192.168.1.144:8000. 2011-11-23 23:22:14 System: Start listening on Socket. 2011-11-23 23:22:17 WebSocket: Resource id #9 CONNECTED! 2011-11-23 23:22:17 WebSocket: Requesting handshake... 2011-11-23 23:22:17 WebSocket: Key: 42MngFcIhXEKCLFloq6IYQ== 2011-11-23 23:22:17 WebSocket: Accept: raRUiMJ6z2bTY6pDrOf7K4Q56Fc= 2011-11-23 23:22:17 WebSocket: Origin: http://192.168.1.144 2011-11-23 23:22:17 WebSocket: Handshaking... 2011-11-23 23:22:17 WebSocket: Done handshaking... 2011-11-23 23:22:18 WebSocket: RECEIVED BEFORE DECODE: ¿õ1ÆÞT 2011-11-23 23:22:18 WebSocket: RECEIVED AFTER DECODE: age 2011-11-23 23:22:18 WebSocket: <age 2011-11-23 23:22:18 WebSocket: >Oh dear, I'm 152 2011-11-23 23:22:18 WebSocket: SENT BEFORE ENCODE: Oh dear, I'm 152 2011-11-23 23:22:18 WebSocket: SENT AFTER ENCODE: ¿õ1Æð
DEBUGGING FROM CLIENT:
Socket Status: 0 Socket Status: 1 (open) Sent: age Received: Oh
ENCODE and DECODE FUNCTIONS
function decode($msg) {
$this->console("RECEIVED BEFORE DECODE: $msg");
$len = $data = $decoded = $index = null;
$len = $msg[1] & 127;
if ($len === 126) {
$this->masks = substr($msg, 4, 4);
$data = substr($msg, 8);
$this->initFrame = substr($msg, 0, 4);
} else if ($len === 127) {
$this->masks = substr($msg, 10, 4);
$data = substr($msg, 14);
$this->initFrame = substr($msg, 0, 10);
} else {
$this->masks = substr($msg, 2, 4);
$data = substr($msg, 6);
$this->initFrame = substr($msg, 0, 2);
}
for ($index = 0; $index < strlen($data); $index++) {
$decoded .= $data[$index] ^ $this->masks[$index % 4];
}
$this->console("RECEIVED AFTER DECODE: $decoded");
return $decoded;
}
function encode($msg) {
$this->console("SENT BEFORE ENCODE: $msg");
$index = $encoded = null;
$len = strlen($msg);
for ($index = 0; $index < $len; $index++) {
$encoded .= $msg[$index] ^ $this->masks[$index % 4];
}
$encoded = $this->initFrame . $this->masks . $encoded;
$this->console("SENT AFTER ENCODE: $encoded");
return $encoded;
}
So, finally found the problem. It was the encode/decode. Or should I say encode. It was encoding the message, but wasn’t following the frame protocol. Below you will find the new encode/decode functions. I did not create these, I found them in another source code, I just don’t remember where. lol