cant use sockets in win32 perl

Posted on 2006-10-24
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 => '',
                                 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 $_;

with the intention of running the sender on another computer


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


but the receiver never connects, always dies with a "could not create socket:  Unknown error" message

what am i doing wrong?
Question by:jephtah
  • 3
  • 2

Author Comment

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 "" 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.

LVL 25

Expert Comment

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

Accepted Solution

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

Not defining the localhost will allow the server to listen for incoming calls on the socket from any ip address.
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.


Author Comment

ID: 17813750
i do not have the firewall enabled.

Author Comment

ID: 17813926

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

LVL 18

Expert Comment

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*

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now