473,624 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Perl Sockets

3 New Member
Hello,

I have created a perl script that connects to a specific socket (Ip address/port) using protocall of TCP. It is the server socket script. There is also coding to manage multiple handles by usung the select() in the coding. This was needed due to the fact we expect a large volume of transactions at any given time on the client's side. The script's purpose is to connect to the client's port and listen for connections, accept the connections, receive the data, then pass the data to an oracle database function, that function returns different data back to the server script, then sends that data back to the client's file handler that it was received on. The client file handler is waiting for that response. The data must be sent back to the same file handler that it was received on. The problem that I am having is that the client is not receiving the data back. I think there may be problem in how the script is coded to send the data back to the same file handler. I have tried all kinds of things and nothing seems to work. maybe the code should be written a different way. I have included the perl code below

If someone could please help me it would be very much appreciated.

Thanks very much,

Randall


<c>#!/usr/bin/perl -w
require 5.002;
use strict;
use IO::Socket;
use IO::Select;
use DBI;
use DBD::Oracle;

our ($dbh);
our ($find_min_requ est_rec, $find_response_ rec);
our ($price_call_re c, $price_response _rec);
our ($find_resp_pr1 ,$find_resp_pr2 ,$find_resp_pr3 );
our ($find_resp_pr4 ,$find_resp_pr5 );
our $read_set ;
our $rh;
our $ns;
our $buf;
our $find_resp;
our $iroam_req_type ;

# Create the receiving socket
my $s = new IO::Socket::INE T (
LocalHost => '172.17.8.201', # IP Address Host to listen on
LocalPort => '18490', # Port Number Host to listen on
Proto => 'tcp',
Listen => 5,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $s;


$read_set = new IO::Select(); # create handle set for reading
$read_set->add($s); # add the main socket to the set

connect_to_orac le_db();

print "At Host/Port listening...\n" ;

while (1) { # Continous Listening on Port for a connection

# get a set of readable handles(blocks until at least one handle is ready)
my ($rh_set) = IO::Select->select($read_s et, undef, undef, 0);

# take all readable handles in turn
foreach $rh (@$rh_set) {
print "Process each readable handle...\n";
print "Value of rh is $rh...\n";
print "Value of rh_set is @$rh_set..\n";
# if it is the main socket then we have an incoming
# connection and we should accept() it and then add
# the new socket to the $read_set
if ($rh == $s) {
print "Main socket/incoming connection add to readable set\n";
$ns = $rh->accept();
$read_set->add($ns); ##already added at beginning
print "Value of rh_set is @$rh_set.after adding connection\n";
# otherwise it is an ordinary socket and we should read
#and process the request
}else{
print "Its an ordinary socket,so read and process the request ...\n";
print "Connected from: ", $rh->peerhost();#Di splay Peer Connection
print " Port: ", $rh->peerport(), "\n";
$buf = <$rh>;
$iroam_req_type = substr($buf,0,8 );#Extract the requestor type
print "Requestor type extracted is: $iroam_req_type \n";#Display Iroam req

if($buf) { # return normal input and process $buf
print "Iroam transaction recd:\n";# Iroam Data
print "$buf\n"; #Display value of the Iroam data from Iroam
if ($iroam_req_typ e =~ /FindMin/){
$find_min_reque st_rec = $buf;
}elsif ($iroam_req_typ e =~ /PriceCall/){
$price_call_rec = $buf;
}
pass_transactio n_to_iroam_pack age();
$rh->send($find_res ponse_rec);
print "rh send value is: $rh->send($find_res ponse_rec) \n";
}else { # the client has closed the socket
print "Iroam client has closed the socket.\n";
# remove the socket from the $read_set and close it
$read_set->remove($rh);
close($rh);
}
}
}
}

sub connect_to_orac le_db{

print "Connect to the Oracle Database sub....\n";

$dbh = DBI->connect(
'DBI:Oracle:dev ',
'perluser',
'oraperl',
{AutoCommit => 0, RaiseError => 1}
) or die "Couldn't connect to database:".DBI->errstr;
}

sub pass_transactio n_to_iroam_pack age{

print "pass transaction to iroam package sub....\n";

my $v_param_iroam_ resp;

if ($iroam_req_typ e =~ /FindMin/){
my $csr = $dbh->prepare(q{
begin
:v_param_iroam_ resp:= WIRELESS_IROAM_ PKG.Lookup_Min_ Request(:find_m in_request_rec) ;
end;
});
$csr->bind_param(":f ind_min_request _rec", $find_min_reque st_rec);
$csr->bind_param_ino ut(":v_param_ir oam_resp", \$v_param_iroam _resp,400);
$csr->execute()
or die "Couldn't exe pass transaction iroam pkg sub ".DBI->errstr;

$find_response_ rec = $v_param_iroam_ resp;

$find_resp_pr1 = substr($find_re sponse_rec ,0,90);
$find_resp_pr2 = substr($find_re sponse_rec ,91,90);
$find_resp_pr3 = substr($find_re sponse_rec ,182,90);
$find_resp_pr4 = substr($find_re sponse_rec ,273,90);
$find_resp_pr5 = substr($find_re sponse_rec ,364,11);

}elsif ($iroam_req_typ e =~ /PriceCall/){
my $csr = $dbh->prepare(q{
begin
:v_param_iroam_ resp:= WIRELESS_IROAM_ PKG.Price_Call( :price_call_rec );
end;
});
$csr->bind_param(":p rice_call_rec", $price_call_rec );
$csr->bind_param_ino ut(":v_param_ir oam_resp", \$v_param_iroam _resp,400);
$csr->execute() or die "Couldn't exe pass iroam pkg sub ".DBI->errstr;

$price_response _rec = $v_param_iroam_ resp;

print "Value of v param iroam resp is: $v_param_iroam_ resp\n";
print "Value of price response is: $price_response _rec \n";

}

print "Processed transaction through the Iroam package\n";

}</c>
Jul 19 '07 #1
0 1599

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2464
by: Chris | last post by:
Hi I am posting this on both the perl and python groups My intention is not to start a war or anything else, I would just like some pragmatic advice. My apologies to the python group I am not very conversant with Python at this stage. that could change soon though.
17
3092
by: Michael McGarry | last post by:
Hi, I am just starting to use Python. Does Python have all the regular expression features of Perl? Is Python missing any features available in Perl? Thanks, Michael
0
6440
by: Danny Jensen | last post by:
I need to test if certain processes on a unix box were running. I wanted to use whatsup gold to do the testing. First I needed to go to the whatsup configure>monitors & services menu to add this tcp/ip port 1555 service with the folowing lines: Send=psef /dj/myco/rf.monitor\r\n Expect=~1 the psef above is a command that the unix server executes. The unix box communicates back a 1 if the test is successful and a 0 if it is
3
21537
by: Daniel Moree | last post by:
I'm attempting to use a perl script to interface with my Visual Basic 6 program using Winsock. I've got my program setup to connect and works great if i connect to another winsock program, but it acts funny connecting to my perl script. The Perl code is below: #!c:/Perl/bin/Perl.exe use IO::Socket; $server = IO::Socket::INET->new(LocalAddr => '10.40.0.10', LocalPort => '8777', Proto => 'tcp',
0
2403
by: muraley | last post by:
Hi, This client-server script does bi-directional communication. Setup i used: The server script on windows 2003 server and the client on a linux machine. Since i faced issues in getting the socket work, i'm posting this. Server Side script: #!/usr/bin/perl -w # serIO.pl
2
1932
by: vj | last post by:
I have a perl script which connect to network stream using sockets. The scripts first logins in to the server and then parses the data comming from the socket. Statement 1: my $today = sprintf("%4s%02s%02s", ->+1900, ->+1, ->) ; Statement 2:
1
2180
by: crawfordr | last post by:
Hello, I have created a perl script that connects to a specific socket (Ip address/port) using protocall of TCP. It is the server socket script. There is also coding to manage multiple handles by usung the select() in the coding. This was needed due to the fact we expect a large volume of transactions at any given time on the client's side. The script's purpose is to connect to the client's port and listen for connections, accept the...
223
7209
by: Pilcrow | last post by:
Given that UNIX, including networking, is almost entirely coded in C, how come so many things are almost impossible in ordinary C? Examples: Network and internet access, access to UNIX interprocess controls and communication, locale determination, EBCDIC/ASCII discrimination, etc. Almost all of these are easy in Perl. Why isn't there a mechanism like perl modules to allow easy extentions for facilities like these? Isn't anyone working...
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.