LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2008, 09:19 AM   #1
gauthamk
Member
 
Registered: Jun 2007
Location: Chennai-India
Posts: 39

Rep: Reputation: 15
Smile Could not create socket: Connection refused in perl


Hello all follwing is the perl scrit.Which tries to create a socket.But whenever I run this progrem I am getting error like [B]Could not create socket: Connection refused.I think this statement is causing this problrm IO::Socket::INET.I think soket creataion is failure.Below is the program that cause this problem .I am running this script on linux machine 2.6.18 kernel and perl vesrion is v5.8.8 .Any help will be appreciated .

#!/usr/bin/perl -w

use strict;
use lib "$ENV{CTI_BASE}/arches/lib";
use TestClass;
use Getopt::Std;
use IO::Socket::INET;
use MfwTemplate;

#Inside of MfwTemplate.pm are the default $cmdopts and @usage parameters.
#If other than the defaults are desired then enter those values here.

#testSetUpAndExecute(\&execute_test,$cmdopts,\@usage);
testSetUpAndExecute(\&execute_test);

# you shouldn't have to change anything above this line, unless you're adding more command line options
# put your new test here
sub execute_test {
my ($test,%opts) = @_;
my $status = "Pass";
my $sdpHeader = pack("CCCCN",0x30,1,1,1,23);
my $sdpCmd = pack("CCCCnN",1,0,0x11,0x40,0,13);
my $sdpData = pack("CNC8",0,64,1,2,3,4,5,6,7,8);
my @header = unpack("CCCCN",$sdpHeader);
printf("SDPHEADER: boardCab:%02x fragId:%02x fragTotal:%02x seqNum:%02x totalCount:%08x\n",
$header[0],$header[1],$header[2],$header[3],$header[4]);
my @cmd = unpack("CCCCnN",$sdpCmd);
printf("SDPCMD: index:%02x modResp:%02x opEndSt:%02x status:%04x dataCount:%08x\n",
$cmd[0],$cmd[2],$cmd[3],$cmd[4],$cmd[5]);
my @d = unpack("CNC8",$sdpData);
printf("SDPDATA: chain:%02x bitCount:%08x\n",
$d[0],$d[1]);
printf("%02x %02x %02x %02x %02x %02x %02x %02x\n",
$d[2],$d[3],$d[4],$d[5],$d[6],$d[7],$d[8],$d[9]);

#Here i am not able to createing soket .

my $sock_out = new IO::Socket::INET (PeerAddr => 'st04a',
PeerPort => 5050,
Proto => 'tcp',Type => SOCK_STREAM
); die "Could not create socket: $!\n" unless $sock_out;






print $sock_out "$sdpHeader";
$sock_out->flush();
}

Last edited by gauthamk; 09-17-2008 at 09:26 AM.
 
Old 09-17-2008, 10:01 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,604

Rep: Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960
Quote:
Originally Posted by gauthamk View Post
Hello all follwing is the perl scrit.Which tries to create a socket.But whenever I run this progrem I am getting error like [B]Could not create socket: Connection refused.I think this statement is causing this problrm IO::Socket::INET.I think soket creataion is failure.Below is the program that cause this problem .I am running this script on linux machine 2.6.18 kernel and perl vesrion is v5.8.8 .Any help will be appreciated .
Is that port open and available?
 
Old 09-17-2008, 10:31 PM   #3
immortaltechnique
Member
 
Registered: Oct 2006
Location: Kenya
Distribution: Ubuntu, RHEL, OpenBSD
Posts: 287

Rep: Reputation: 32
This code tries to open a connection to port 5050 of a machine called st04a. The error message says it can't get a connection, so you might test that:
First try "ping st04a" on the command line. If st04a answers then that isn't the problem. Otherwise the name is wrong, your nameserver doesn't know st04a in your network or st04a is down
Now you should check whether there is a server behind port 5050. If "telnet st04a 5050" returns "Connection refused" then you have to restart whatever server process is listening on port 5050 of machine st04a.
 
Old 09-18-2008, 10:18 AM   #4
gauthamk
Member
 
Registered: Jun 2007
Location: Chennai-India
Posts: 39

Original Poster
Rep: Reputation: 15
Smile Could not create socket: Connection refused in per

Thanks u for u r reply.I checked to telnet as u said.telnet st04a 5050
But it could able to make the connection .Even checked and ensured that the port is free .Even whwn I tries to ping st04a .pininging is failing .
 
Old 09-18-2008, 10:52 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,604

Rep: Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960
Quote:
Originally Posted by gauthamk View Post
Thanks u for u r reply.I checked to telnet as u said.telnet st04a 5050
But it could able to make the connection .Even checked and ensured that the port is free .Even whwn I tries to ping st04a .pininging is failing .
Then the first thing you need to do, is to resolve your network issue(s) between your two hosts. Also, please try to write and spell clearly, it helps everyone understand what you're trying to say.
 
Old 09-18-2008, 11:46 AM   #6
immortaltechnique
Member
 
Registered: Oct 2006
Location: Kenya
Distribution: Ubuntu, RHEL, OpenBSD
Posts: 287

Rep: Reputation: 32
You might also try putting

Reuse=>1,

in your IO::Socket options. Without that, there may be a delay in clearing the port and you would get a no connect error after the first connect.
 
Old 09-25-2008, 02:20 AM   #7
gauthamk
Member
 
Registered: Jun 2007
Location: Chennai-India
Posts: 39

Original Poster
Rep: Reputation: 15
Once again Thanks for u r reply.Hai I chaged the hsot address from st04a to st04a.fc.hp.com .I am able to ping and I am able to telnet to this site .As u said I also used Reuse=>.But still the socket creation is not happenning .Even I tried "telnet st04a.fc.hp.com 5050" This also fails.
U can check this statement.

my $sock_out = new IO::Socket::INET (PeerAddr => 'st04a.fc.hp.com',
PeerPort => '5050',
Proto => 'tcp',#Type => SOCK_STREAM
Reuse =>1
); die "Could not create socket: $!\n" unless $sock_out;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket Connection Failed: 111 Connection Refused degraffenried13 Linux - General 3 05-31-2009 01:17 AM
IO:Socket error:Connection refused nsfocus Programming 12 05-27-2008 12:16 AM
connection between java socket and unix socket sathishkumar Programming 1 01-10-2006 03:21 PM
Socket connection refused problem James_dean Linux - Networking 1 09-23-2005 04:51 PM
Socket Application: Connection refused Agent007 Linux - Networking 1 01-27-2004 12:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration