Hello, JNP> In your Event tutorial, you mention on using non-blocking socket JNP> using IPC::LDT perl module. I try to use but encounter errors on JNP> the receive. here's my snipprt code. I hope u can point out my JNP> errors.
I don't know the errors that occurred, but here is a slightly reworked
version of your code that I could run successfully:
- snip --
# precondition to make IPC::LDT::new(traceMode=>1) work
BEGIN {$IPC::LDT::Trace=1;}
# load modules
use Event;
use IPC::LDT;
use IO::Socket;
# make socket
my $socket=IO::Socket::INET->new(Listen=>5, LocalPort=>8001, Reuse=>1);
die "[Fatal] Cannot build initial socket.\n" unless $socket;
DEBUG && print ("start smpp service\n");
# install an initial watcher
Event->io(
fd => $socket,
cb => sub {
# make "channel" number
my $channel=++$channels;
# accept client
my $client=$socket->accept;
warn "[Error] Cannot connect to new client.\n" and return unless
$client;
$client->autoflush;
# install a communicator
Event->io(
fd => $client,
cb => sub {
# report
warn "[Server] Talking on channel $channel.\n";
my $ldt = new IPC::LDT(handle=>$_[0]->w->fd,
traceMode=>1);
my $msg = $ldt->receive() or die $ldt->{'msg'};
warn "[Channel 1] $msg\n";
if ( $msg =~ /quit$/i){
warn "[Server] Closing
channel $channel.\n";
$_[0]->w->cancel;
}
}
);
# welcome
$client->print("Welcome, this is Channel $channel.\n");
# report
warn "[Server] Opened new channel $channel.\n";
},
);
# start loop
Event::loop;
- snip --
To talk with this server, one needs to use IPC::LDT as well (or to
emulate its protocol). For example, I used the Perl debugger, like
so:
- snip --
> use IO::Socket::INET
> use IPC::LDT
> $s1=new IO::Socket::INET(PeerAddr=>'localhost:8001')
> $ldt1=new IPC::LDT(handle=>$s1)
> $ldt1->send("Hi, there!")
> $s2=new IO::Socket::INET(PeerAddr=>'localhost:8001')
> $ldt2=new IPC::LDT(handle=>$s2)
> $ldt2->send("Nice to talk to you!")
> $ldt1->send('quit')
> $ldt2->send('quit')
- snip --
I suppose the usage of IPC::LDT in the *client* was the important
point here, was it? Could you please try if it works for you this way?
Jochen
pgpC9b3BNqSlG.pgp
Description: PGP signature
