#!/usr/bin/perl -w require 5.002; use strict; use IO::Socket; use IO::Select; our ($find_min_request_rec, $find_response_rec, $price_call_rec); our $read_set ; our $rh; our $ns; our $buf; our $iroam_req_type; # Create the receiving socket my $s = new IO::Socket::INET ( LocalHost => '172.17.8.201', LocalPort => '18490', Proto => 'tcp', Listen => 5, Reuse => 1, ); die "Could not create socket: $!\n" unless $s; $read_set = new IO::Select(); # create handle set $read_set->add($s);# add main socket to the set print "At Host/Port listening. Waiting to receive transactions..\n"; while (1) { # Continous Listening on Port # get a set of readable handles my ($rh_set) = IO::Select->select($read_set, undef, undef, 0); # take all readable handles in turn foreach $rh (@$rh_set) { print "Process each readable handle...\n"; if ($rh == $s) { print "Main socket/incoming connection..\n"; $ns = $rh->accept(); $read_set->add($ns); # otherwise it is an ordinary socket and # we should read and process the request }else{ print "An ordinary socket..\n"; print "Connected from: ", $rh->peerhost(); print " Port: ", $rh->peerport(), "\n"; $buf = <$rh>; $iroam_req_type = substr($buf,0,8); if($buf) { # return normal input and process $buf if ($iroam_req_type =~ /FindMin/){ $find_min_request_rec = $buf; }elsif ($iroam_req_type =~ /PriceCall/){ $price_call_rec = $buf; } $find_response_rec = 'GCD 0003002296392 ENGLISH YNNNNN000024160000'; $rh->send($find_response_rec); }else { # the client has closed the socket $read_set->remove($rh); close($rh); } } } } #### #!/usr/bin/perl use strict; use IO::Socket; our $iroam_req = 'FindMin TLK 91271558098436895219S 95TestRSU333333333 888888885555520070718103045'; our($sock); main_process(); sub main_process{ print "main process sub....\n"; open_socket(); print $sock $iroam_req; ####close($sock); ###sleep 5; ###open_socket(); ###print $sock $iroam_req; ###close($sock); ###sleep 5; } sub open_socket{ $sock = new IO::Socket::INET ( PeerHost=> '172.17.8.201', PeerPort => '18490', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock; }