To narrow down on the issue, I would run the program under strace to figure out which system call is actually failing...

On my machine (where your (slightly adapted) code does work), the last lines I get are

... socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3 ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa99308) = -1 EINVAL (Inval +id argument) _llseek(3, 0, 0xbfa99350, SEEK_CUR) = -1 ESPIPE (Illegal seek) ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa99308) = -1 EINVAL (Inval +id argument) _llseek(3, 0, 0xbfa99350, SEEK_CUR) = -1 ESPIPE (Illegal seek) fcntl64(3, F_SETFD, FD_CLOEXEC) = 0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 bind(3, {sa_family=AF_INET, sin_port=htons(7070), sin_addr=inet_addr(" +0.0.0.0")}, 16) = 0 listen(3, 1) = 0 accept(3,

It could be one of fcntl, setsockopt, bind or listen failing (all may potentially set EBADF). Then, depending on which one it is, look in the respective man page. If you're lucky, you might find something resembling an explanation...


In reply to Re: Could not create socket: Bad file number by almut
in thread Could not create socket: Bad file number by perlofwisdom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.