473,396 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Perl Sockets

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_request_rec, $find_response_rec);
our ($price_call_rec, $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::INET (
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_oracle_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_set, 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();#Display 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_type =~ /FindMin/){
$find_min_request_rec = $buf;
}elsif ($iroam_req_type =~ /PriceCall/){
$price_call_rec = $buf;
}
pass_transaction_to_iroam_package();
$rh->send($find_response_rec);
print "rh send value is: $rh->send($find_response_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_oracle_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_transaction_to_iroam_package{

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

my $v_param_iroam_resp;

if ($iroam_req_type =~ /FindMin/){
my $csr = $dbh->prepare(q{
begin
:v_param_iroam_resp:= WIRELESS_IROAM_PKG.Lookup_Min_Request(:find_min_re quest_rec);
end;
});
$csr->bind_param(":find_min_request_rec", $find_min_request_rec);
$csr->bind_param_inout(":v_param_iroam_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_response_rec ,0,90);
$find_resp_pr2 = substr($find_response_rec ,91,90);
$find_resp_pr3 = substr($find_response_rec ,182,90);
$find_resp_pr4 = substr($find_response_rec ,273,90);
$find_resp_pr5 = substr($find_response_rec ,364,11);

}elsif ($iroam_req_type =~ /PriceCall/){
my $csr = $dbh->prepare(q{
begin
:v_param_iroam_resp:= WIRELESS_IROAM_PKG.Price_Call(:price_call_rec);
end;
});
$csr->bind_param(":price_call_rec", $price_call_rec);
$csr->bind_param_inout(":v_param_iroam_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 1589

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

Similar topics

7
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...
17
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
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...
3
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...
0
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...
2
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 =...
1
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...
223
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.