public function write($code, $message = null)
{
if (!is_resource($this->stream)) {
return;
}
if (!is_int($code) || 0 > $code || 6 < $code) {
throw new InvalidArgumentException('Wrong message type when trying to write on the socket');
}
$payload = new Encoder($code . $message, Encoder::OPCODE_TEXT, true);
$bytes = fwrite($this->stream, (string) $payload);
// wait a little bit of time after this message was sent
usleep((int) $this->options['wait']);
return $bytes;
}