class Receiver
Public Class Methods
new(parent = nil)
click to toggle source
Calls superclass method
# File examples/network/broadcastreceiver/receiver.rb, line 31 def initialize(parent = nil) super(parent) @statusLabel = Qt::Label.new(tr("Listening for broadcasted messages")) @quitButton = Qt::PushButton.new(tr("&Quit")) @udpSocket = Qt::UdpSocket.new(self) @udpSocket.bind(45454) connect(@udpSocket, SIGNAL(:readyRead), self, SLOT(:processPendingDatagrams)) connect(@quitButton, SIGNAL(:clicked), self, SLOT(:close)) buttonLayout = Qt::HBoxLayout.new do |b| b.addStretch(1) b.addWidget(@quitButton) end self.layout = Qt::VBoxLayout.new do |m| m.addWidget(@statusLabel) m.addLayout(buttonLayout) end self.windowTitle = tr("Broadcast Receiver") end
Public Instance Methods
processPendingDatagrams()
click to toggle source
# File examples/network/broadcastreceiver/receiver.rb, line 56 def processPendingDatagrams() while @udpSocket.hasPendingDatagrams do datagram = Qt::ByteArray.new datagram.resize(@udpSocket.pendingDatagramSize) @udpSocket.readDatagram(datagram.data(), datagram.size()) @statusLabel.text = tr('Received datagram: "%d"' % datagram.data) end end