Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 682
  • Last Modified:

Sockets

Hello,
I've found this in a book, but can't get it to work.

Code:
open_SOCKET($server, 80);
sub open_SOCKET {
  my ($server, $port) = @_;
  $port = getservbyname($port, 'tcp') if $port !~ /^[0-9]/;
  socket SOCKET, AF_INET, SOCK_STREAM, 0 or die "open socket: $!";
  connect(SOCKET, sockaddr_in($port, inet_aton($server)));
}

Error:
Argument "SOCK_STREAM" isn't numeric in socket
Argument "AF_INET" isn't numeric in socket

Output:
open socket: Unknown Error: 0x0000273c

Martin
0
martinag
Asked:
martinag
  • 2
  • 2
1 Solution
 
ozoCommented:
Did you
 use Socket;
to get the proper definitions imported?

0
 
martinagAuthor Commented:
No I didn't...Claim you points, ozo.

But why weren't AF_INET and SOCK_STREAM undefined?

Martin
0
 
ozoCommented:
With
  no strict 'subs';
an undefiled bareword is treated as if it were a quoted string
(the -w switch will warn you about these)
0
 
martinagAuthor Commented:
Ok, thanks.

Martin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now