Debugging IO::Socket Not Connecting


 
Thread Tools Search this Thread
Top Forums Programming Debugging IO::Socket Not Connecting
# 1  
Old 06-10-2010
Debugging IO::Socket Not Connecting

I'm using perl to connect to a port on a unix box from a windows machine. The unix box is located in a remote office and I'm able to connect just fine from my desktop at work across the network. But if I try to remote to another windows machine at the same location as the unix box and try to connect to the port, I get no connection.

Code:
use IO::Socket;
my $sock = new IO::Socket::INET(
   'PeerAddr' => 'xx.xx.xx.xx',
   'PeerPort' => 26637,
   'Proto' => 'tcp',
);
if ($sock) {
   print "Connection established\n";
} else {
   print "Could not connect!\n";
}

For the PeerAddr, I've tried all variations of the address. Is there some way to get an error code from the failed constructor? I have no idea why it failed (can't find the host, port not accepting connections, etc). Anything else I should try?
# 2  
Old 06-10-2010
Can you ping the remote Windows machine?
Is the port you have defined open? (nmap)
If it's open, maybe it's firewalled or something?

Try:
Code:
   print "Could not connect! Reason: $!\n";

# 3  
Old 06-10-2010
The port is open. I'm able to connect from my pc at my office. The unix machine is located in another office in another state. If I try to connect to unix from windows using a pc in the other office, no connection is made. I am able to telnet to the unix machine using the remote windows machine. And I can ping the pc from unix.
# 4  
Old 06-14-2010
did you try what the previous post said, i.e. the $! which gives the system message?

you should also have
Code:
my $sock = new IO::Socket::INET(
   'PeerAddr' => 'xx.xx.xx.xx',
   'PeerPort' => 26637,
   'Proto' => 'tcp',
   reuse => 1,
);

here's why...
Code:
What exactly does SO_REUSEADDR do? 
  This socket option tells the kernel that even if this port is busy (in
  the TIME_WAIT state), go ahead and reuse it anyway.  If it is busy,
  but with another state, you will still get an address already in use
  error.  It is useful if your server has been shut down, and then
  restarted right away while sockets are still active on its port.  You
  should be aware that if any unexpected data comes in, it may confuse
  your server, but while this is possible, it is not likely.

also, you don't need the quotes on the LHS of a
Code:
=>

because
Code:
x=>y

is shorthand for
Code:
"x", y

# 5  
Old 06-14-2010
Yes. $! gives Unknown error. Not too helpful. I also tried Reuse => 1 and it took longer, but still gave the same result. If it is a firewall issue, why can I connect from my pc, but not one in the same office as the unix server? Anyone know of another module to test connections that will give more details?
# 6  
Old 06-21-2010
It was a firewall issue. How do you mark these threads closed?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

c++ debugging

hey i have a problem with a switch case in program and the debugger is messy has hell ( we use normal VI and gdb in our schoool to make it more diffiacult) any way i have a problom where for some unknown reason the debugger just skips a switch statment as if it wasent even there the rest... (2 Replies)
Discussion started by: gotenxds
2 Replies

2. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies

3. Programming

Error with socket operation on non-socket

Dear Experts, i am compiling my code in suse 4.1 which is compiling fine, but at runtime it is showing me for socket programming error no 88 as i searched in errno.h it is telling me socket operation on non socket, what is the meaning of this , how to deal with this error , please... (1 Reply)
Discussion started by: vin_pll
1 Replies

4. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

5. Programming

which socket should socket option on be set

Hi all, On the server side, one socket is used for listening, the others are used for communicating with the client. My question is: if i want to set option for socket, which socket should be set on? If either can be set, what's the different? Again, what's the different if set option... (1 Reply)
Discussion started by: blademan100
1 Replies

6. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

7. Solaris

debugging

when I tried to debug my application i got the following. gdb -v GNU gdb 6.6 file is in C and Xmotiff Languages (gdb) attach 25499 Attaching to process 25499 Retry #1: Retry #2: Retry #3: Retry #4: 0xfea40b68 in ?? () (gdb) where #0 0xfea40b68 in ?? () (0 Replies)
Discussion started by: satish@123
0 Replies

8. Programming

Problem Connecting to Socket

Can anyone help? I'm trying to write a program which will write to a socket. I can get the server to run, but always get an error when I try to connect. It gives me an error at the "connect" command. It's probably a simple error, but I can't seem to find it. #include <sys/socket.h>... (6 Replies)
Discussion started by: Stevhp
6 Replies

9. Shell Programming and Scripting

Regarding Debugging

Hi, If we want to debug a shell script, then set -vx has to be included in the begining of the script. Just i want to know what purpose -vx is used. Thanks in advace Sarwan (2 Replies)
Discussion started by: sarwan
2 Replies

10. Programming

Socket Programming socket

Hello, I actually try to make client-server program. I'm using SCO OpenServer Release 5.0.0 and when I try to compile my code (by TELNET) I've got this error : I'm just using this simple code : and I get the same error if I use : If someone can help me, Thanks (2 Replies)
Discussion started by: soshell
2 Replies
Login or Register to Ask a Question