public function __construct(InetAddress $ipAddress, $portNumber) { parent::__construct($ipAddress, $portNumber); $this->buffer = ByteBuffer::allocate(1400); $this->channel = SocketChannel::open(); $this->remoteSocket = array($ipAddress, $portNumber); }
public function testReceiveIntoExistingBuffer() { $this->socket->buffer = ByteBuffer::allocate(10); $this->udpSocket->expects($this->once())->method('select')->will($this->returnValue(true)); $this->udpSocket->expects($this->once())->method('recv')->with(4)->will($this->returnValue('test')); $this->assertEquals(4, $this->socket->receivePacket(4)); $buffer = $this->socket->buffer; $this->assertEquals(0, $buffer->position()); $this->assertEquals(4, $buffer->remaining()); $this->assertEquals('test', $buffer->_array()); }
/** * @return int */ public function receivePacket($bufferLength = 0) { if (!$this->channel->socket()->select(1)) { throw new TimeoutException(); } if ($bufferLength == 0) { $this->buffer->clear(); } else { $this->buffer = ByteBuffer::allocate($bufferLength); } $this->channel->read($this->buffer); $bytesRead = $this->buffer->position(); $this->buffer->rewind(); $this->buffer->limit($bytesRead); return $bytesRead; }
/** * @return int */ public function receivePacket($bufferLength = 0) { if (!$this->socket->select(self::$timeout)) { throw new TimeoutException(); } if ($bufferLength == 0) { $this->buffer->clear(); } else { $this->buffer = ByteBuffer::allocate($bufferLength); } $data = $this->socket->recv($this->buffer->remaining()); $this->buffer->put($data); $bytesRead = $this->buffer->position(); $this->buffer->rewind(); $this->buffer->limit($bytesRead); return $bytesRead; }
public function __construct(InetAddress $ipAddress, $portNumber) { $this->buffer = ByteBuffer::allocate(1400); $this->ipAddress = $ipAddress; $this->portNumber = $portNumber; }