sanjay nayak has asked for the wisdom of the Perl Monks concerning the following question:
use IO::Socket::INET; use strict; use Config::Tiny; use Config::Random; my ($DATA,$text,$msg, $array1); my @array; open TESTCASE, "imp2.txt" or die $!; while(<TESTCASE>) { $array1 = $_; chomp $array1; $array[$incre]= $array1; $incre++; } open CONFIGFILE, "imp1.txt" or die $!; { local $/; $/ = undef; $DATA=<CONFIGFILE>; } my $Config = Config::ACTI->new(); $Config = Config::ACTI->read_string( $DATA ); $s = $Config->{_}; my $method= <<END; REGISTER sip: 36.212.176.07 SIP/2.0\r Via: SIP/2.0/UDP 36.212.176.90:5060; branch= z9hg4bk340\r To: sanjay<sip:userA@36.212.176.90>\r From:sanjay<sip:userA@36.212.176.90>;tag= abcd1250\r Max-Forwards: 70\r Call-ID: abchjhg1560@36.212.176.90\r CSeq: 1 REGISTER\r Contact:sanjay<sip:userA@36.212.176.90>; expires=7200\r Content-Length:0\r \r END my $MySocket=new IO::Socket::INET->new( LocalAddr=>$s->{Local_IP}, LocalPort=>$s->{LocalPort}, PeerPort=>$s->{RemotePort}, Proto=>$s->{Transport}, PeerAddr=>$s->{Remote_IP} ); $MySocket or die "no socket :$!"; print "\nClient Started: Ready For Packet To Send:\n"; my $incre = 0; COND:for(;;) { last if $array[$incr] eq ''; if ($array[$incr] eq "[SEND]") { $incr++; if ($array[$incr] eq ("REGISTER" || "INVITE" || "ACK" || "BYE" || + "OPTION" || "CANCEL")) { $incr++; goto OUTER; } else { print "Bad Request :$array[$incr]"; exit 1; } } elsif ($array[$incr] eq "[RECV]") { $incr++; if($array[$incr] == (100 || 200 || 300 || 400)) { $incr++; goto INNER; } else { print "Bad Response name:$array[$incr]"; exit 1; } } else { print "Bare word found:"; exit 1; } } OUTER:for(;;) { my $msg=$method; print "\nSending message:$msg"; $MySocket->send($msg); goto COND; } INNER:for(;;) { print "Waiting for Response:\n"; $MySocket->recv ($text,1000);#///Recv print "\nReceived message From:$text"; goto COND; }
[SEND] REGISTER [RECV] 100 [RECV] 200
2006-08-30 Retitled by holli, as per Monastery guidelines
Original title: 'plz, suggest me any suitable code for it???'
Edited by planetscape - added readmore tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to replace 'goto' by another construct?
by Hofmator (Curate) on Aug 30, 2006 at 08:23 UTC | |
|
Re: How to replace 'goto' by another construct?
by shmem (Chancellor) on Aug 30, 2006 at 08:17 UTC | |
|
Re: How to replace 'goto' by another construct?
by Leviathan (Scribe) on Aug 30, 2006 at 08:15 UTC |