28 public function __construct(
32 public function onClientConnect(
int $sessionId,
string $address,
int $port,
int $clientId) :
void{
33 $rawAddr = inet_pton($address);
34 if($rawAddr ===
false){
35 throw new \InvalidArgumentException(
"Invalid IP address");
37 $this->channel->write(
38 chr(ITCProtocol::PACKET_OPEN_SESSION) .
39 Binary::writeInt($sessionId) .
40 chr(strlen($rawAddr)) . $rawAddr .
41 Binary::writeShort($port) .
42 Binary::writeLong($clientId)
47 $this->channel->write(
48 chr(ITCProtocol::PACKET_CLOSE_SESSION) .
49 Binary::writeInt($sessionId) .
54 public function onPacketReceive(
int $sessionId,
string $packet) : void{
55 $this->channel->write(
56 chr(ITCProtocol::PACKET_ENCAPSULATED) .
57 Binary::writeInt($sessionId) .
62 public function onRawPacketReceive(
string $address,
int $port,
string $payload) : void{
63 $this->channel->write(
64 chr(ITCProtocol::PACKET_RAW) .
65 chr(strlen($address)) . $address .
66 Binary::writeShort($port) .
71 public function onPacketAck(
int $sessionId,
int $identifierACK) : void{
72 $this->channel->write(
73 chr(ITCProtocol::PACKET_ACK_NOTIFICATION) .
74 Binary::writeInt($sessionId) .
75 Binary::writeInt($identifierACK)
79 public function onBandwidthStatsUpdate(
int $bytesSentDiff,
int $bytesReceivedDiff) : void{
80 $this->channel->write(
81 chr(ITCProtocol::PACKET_REPORT_BANDWIDTH_STATS) .
82 Binary::writeLong($bytesSentDiff) .
83 Binary::writeLong($bytesReceivedDiff)
87 public function onPingMeasure(
int $sessionId,
int $pingMS) : void{
88 $this->channel->write(
89 chr(ITCProtocol::PACKET_REPORT_PING) .
90 Binary::writeInt($sessionId) .
91 Binary::writeInt($pingMS)