Solved

cant use sockets in win32 perl

Posted on 2006-10-24
6
271 Views
Last Modified: 2010-05-18
win32 perl 5.8.8

trying to use IO::Sockets to open up a tcp connection, to just do a simple communication between two computers on the same subnet.

first i run the receiver on one computer:

=========================
use IO::Socket;
my $sock = new IO::Socket::INET (
                                 LocalHost => '192.168.1.186',
                                 LocalPort => 9000,
                                 Proto => 'tcp',
                                 Listen => 1,
                                 Reuse => 1,
                                );
die "Could not create socket: $!\n" unless $sock;
   
my $new_sock = $sock->accept();
while(<$new_sock>) {
   print $_;
}
close($sock);
================================

with the intention of running the sender on another computer

================================
 

use IO::Socket;
my $sock = new IO::Socket::INET (
                                 PeerAddr => '192.168.1.183',
                                 PeerPort => 9000,
                                 Proto => 'tcp'
                                );
die "Could not create socket: $!\n" unless $sock;
print $sock "Hello there!\n";

$answer=<$sock>;

close($sock);
 
===============================
   
but the receiver never connects, always dies with a "could not create socket:  Unknown error" message

what am i doing wrong?
0
Comment
Question by:jephtah
  • 3
  • 2
6 Comments
 

Author Comment

by:jephtah
ID: 17800441
if i change both hostnames to "localhost" and do it all on one computer (two terminal windows), it works correctly.

if i change peer address to "www.yahoo.com" and peer port to 80, it sends my little packet to yahoo, and i get back a 'bad html request' answer from them.

i think maybe i dont have my computers set up to accept traffic on the ports correctly or something...   i am behind my company's firewall, but being on the same subnet, it shouldnt matter.  in fact, both computers are physically sharing the same switch port, via a simple hub.  i tried to set ports open on my network settings, but apparently it didnt do what i hoped it would do.





0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 17800627
You probably have XP SP2 installed and the firewall enabled.
0
 
LVL 18

Accepted Solution

by:
Morcalavin earned 125 total points
ID: 17802840
Take this out:
LocalHost => '192.168.1.186',

Not defining the localhost will allow the server to listen for incoming calls on the socket from any ip address.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:jephtah
ID: 17813750
i do not have the firewall enabled.
0
 

Author Comment

by:jephtah
ID: 17813926
MORCALAVIN:  

ok, that works, but i dont understand why the LocalHost has to be removed.  all of the examples for IO::Socket specify a LocalHost.  

0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 17813954
I'm not entirely sure as I'm not a socket genius, but I had this same problem in a perl socket program and a c# socket program.  Specifying the localip address as your localhost would only allow you, the localhost, to send to the socket.  I guess localhost defines the server your listenting for, not what server you are listening on.  *shrugs*
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expect & sshpass package for Solaris 10 x86 15 961
rename outfile before writing 2 74
Perl: How to add backslashes to every period in a string 1 35
perl syntax 3 16
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question