Socket AGI

I want to create a script with perl or php, that send packet from asterisk to socket listing.

I use trixbox and i install the perl-Net-Telnet library with this command :
yum -y install perl-Net-Telnet

the script is located in this directory :
/var/lib/asterisk/agi-bin/

testPerl.pl

#!/usr/bin/perl -w

    $server_ip='10.0.10.11';

    $tn = new Net::Telnet (Port => 30000,
                            Prompt => '/.*[\$%#>] $/',
                            Output_record_separator => '',
                            Errmode    => 'return'
                            );


    #Connect
    $tn->open("$server_ip");
    $tn->print("Test");
  
     exit;

In the dialplan i wrote :
exten => 52,1,agi(testPerl.pl)

Other script that don’t work …

#!/usr/bin/perl
use IO::Socket;
IO::Socket::INET->new(PeerAddr => “10.0.10.11” . (defined $ARGV[1] ? $ARGV[1] : “30000”), Proto => “tcp”)->send(“bye”,MSG_OOB);

Can you help me ?? please.

Best is to use the already available PHP or Perl libraries:

phpagi.sourceforge.net
voip-info.org/wiki/view/Aste … rl+library

With perl or php library i can open a socket for connect to a other computer, or library can only develop for dialplan ?

thanks.

[quote=“GabrieleC”]With perl or php library i can open a socket for connect to a other computer, or library can only develop for dialplan ?

thanks.[/quote]

The AGI is primarily intended for the Dialplan development, although EAGI does exist for handling the voice channel as well.

muppetmaster wrote :
The AGI is primarily intended for the Dialplan development …

AGI is primarily intended for the dialplan, but don’t only intended for the dialplan, right ?? I can wrote a script with php that open a socket, this is a script in php.

pippo.php

#!/usr/bin/php

<? $socket = fsockopen( "10.0.10.11",30000, $errno, $errstr); if (!$socket) { print $errstr."(".$errno.")\n"; // i think that send text to asterisk console exit; } print "Socket open"; // i think that send text to asterisk console fputs($socket, "Send Data\r\n"); fclose($socket); exit; ?>

In the dialplan i wrote :

exten => 54,1,SayNumber(54)
exten => 54,2,AGI(pippo.php)

but don’t work.
The ip of socket listening is 10.0.10.11 and port is 30000.

The problem is only script because with command telnet work fine.

can you help me, please!!