public function connect(WritableStreamInterface $stream, $lastId = null) { if ($lastId !== null) { for ($i = $lastId; isset($this->bufferedData[$i]); ++$i) { $stream->write($this->encoder->encodeMessage($this->bufferedData[$i], isset($this->bufferedType[$i]) ? $this->bufferedType[$i] : null, $i)); } } $this->streams[] = $stream; }
public function __construct(WritableStreamInterface $socket) { $this->_socket = $socket; $this->_id = uniqid("connection-"); $that = $this; $buffer = ''; $socket->on("data", function ($data) use($that, &$buffer) { $buffer .= $data; $that->handleData($buffer); }); $socket->on("close", function ($data) use($that) { $that->emit("close", func_get_args()); }); }