| Billy Ray Padgett 2004-12-02, 9:09 pm |
| On Thu, 02 Dec 2004 18:32:55 +0000, Ala Qumsieh wrote:
> roho50@hotmail.com wrote:
>
> The reason is that recv() blocks until it gets 1024 bytes worth of data.
>
>
> It depends on how you're doing it. Since you don't show any code, it's
> kind of hard to suggest anything. One thing you can do is to use
> IO::Select to check if your socket has anything worth reading. If so,
> then read whatever is in the socket into a buffer, and check the size of
> the buffer until you reach 1024 bytes (or whatever you want).
>
> Check 'perldoc IO::Select' for more information and for sample code.
>
> --Ala
<my code. ROHO50 is because we're blocked by a firewall at work.
Thanks!
> #!/usr/bin/perl -w
use strict;
use utf8;
package MyDialog;
use Qt;
use Qt::isa qw(Qt::Dialog);
use Qt::slots
CountLoop => [],
sockloop => [];
use Qt::attributes qw(
buttonHelp
buttonOk
buttonCancel
pushButton5
lcd2
lcd1
lineEdit1
pushButton4
);
sub NEW
{
shift->SUPER::NEW(@_[0..3]);
if ( name() eq "unnamed" )
{
setName("MyDialog" );
}
setSizeGripEnabled(1 );
my $LayoutWidget = Qt::Widget(this, '$LayoutWidget');
$LayoutWidget->setGeometry( Qt::Rect(20, 240, 476, 33) );
my $Layout1 = Qt::HBoxLayout($LayoutWidget, 0, 6, '$Layout1');
buttonHelp = Qt::PushButton($LayoutWidget, "buttonHelp");
buttonHelp->setAutoDefault( 1 );
$Layout1->addWidget(buttonHelp);
my $spacer = Qt::SpacerItem(20, 20, &Qt::SizePolicy::Expanding, &Qt::SizePolicy::Minimum);
$Layout1->addItem($spacer);
buttonOk = Qt::PushButton($LayoutWidget, "buttonOk");
buttonOk->setAutoDefault( 1 );
buttonOk->setDefault( 1 );
$Layout1->addWidget(buttonOk);
buttonCancel = Qt::PushButton($LayoutWidget, "buttonCancel");
buttonCancel->setAutoDefault( 1 );
$Layout1->addWidget(buttonCancel);
pushButton5 = Qt::PushButton(this, "pushButton5");
pushButton5->setGeometry( Qt::Rect(200, 70, 114, 31) );
lcd2 = Qt::LCDNumber(this, "lcd2");
lcd2->setGeometry( Qt::Rect(200, 10, 121, 31) );
lcd2->setPaletteForegroundColor( Qt::Color(0, 255, 127) );
lcd2->setPaletteBackgroundColor( Qt::Color(0, 0, 0) );
lcd2->setSegmentStyle( &Qt::LCDNumber::Flat() );
lcd1 = Qt::LCDNumber(this, "lcd1");
lcd1->setGeometry( Qt::Rect(30, 10, 121, 31) );
lcd1->setPaletteForegroundColor( Qt::Color(0, 255, 127) );
lcd1->setPaletteBackgroundColor( Qt::Color(0, 0, 0) );
lcd1->setSegmentStyle( &Qt::LCDNumber::Flat() );
lineEdit1 = Qt::LineEdit(this, "lineEdit1");
lineEdit1->setGeometry( Qt::Rect(200, 40, 311, 31) );
pushButton4 = Qt::PushButton(this, "pushButton4");
pushButton4->setGeometry( Qt::Rect(30, 70, 115, 31) );
languageChange();
my $resize = Qt::Size(511, 282);
$resize = $resize->expandedTo(minimumSizeHint());
resize( $resize );
clearWState( &Qt::WState_Polished );
Qt::Object::connect(buttonOk, SIGNAL "clicked()", this, SLOT "accept()");
Qt::Object::connect(buttonCancel, SIGNAL "clicked()", this, SLOT "reject()");
Qt::Object::connect(pushButton4, SIGNAL "clicked()", this, SLOT "CountLoop()");
Qt::Object::connect(pushButton5, SIGNAL "clicked()", this, SLOT "sockloop()");
}
# Sets the strings of the subwidgets using the current
# language.
sub languageChange
{
setCaption(trUtf8("MyDialog") );
buttonHelp->setText( trUtf8("&Help") );
buttonHelp->setAccel( Qt::KeySequence( trUtf8("F1") ) );
buttonOk->setText( trUtf8("&OK") );
buttonOk->setAccel( Qt::KeySequence( "" ) );
buttonCancel->setText( trUtf8("&Cancel") );
buttonCancel->setAccel( Qt::KeySequence( "" ) );
pushButton5->setText( trUtf8("Socket Loop") );
pushButton4->setText( trUtf8("Count up") );
}
sub CountLoop
{
my $i;
$i=lcd1->value();
$i++;
lcd1->display($i);
}
sub sockloop
{
use IO::Socket;
my ($sock,$trap,$MAX,$portNum,$x);
$MAX=1024;
$portNum=4162;
$x=1;
print "Creating socket...\n";
$sock = IO::Socket::INET->new(LocalPort => $portNum, Proto => 'udp')
or die "socket: $@";
print "Socket created!\n";
while ($sock->recv($trap, $MAX)) {
print "**TRAP RECEIVED**\n";
lcd2->display($x);
lineEdit1->setText($trap);
lcd2->repaint(1);
lineEdit1->repaint(1);
this->repaint(1);
$x++;
}
}
1;
package main;
use Qt;
use MyDialog;
my $a = Qt::Application(\@ARGV);
my $w = MyDialog;
$a->setMainWidget($w);
$w->show;
exit $a->exec;
|