Here's the sockets code: SERVER
socket(PEERS, AF_INET, SOCK_STREAM, $protocol) or die "socket() failed +: $!"; setsockopt(PEERS,SOL_SOCKET,SO_REUSEADDR,1) or die "Can't set SO_RE +USADDR: $!" ; my $my_peer_addr = sockaddr_in($peerport,INADDR_ANY); bind(PEERS,$my_peer_addr) or die "bind() failed: $!"; listen(PEERS,SOMAXCONN) or die "listen() failed: $!"; warn "Waiting for Peer Servers on $peerport\n"; ######################################### # SET UP FILE TRANSFER SOCKET ######################################### socket(SERVER, AF_INET, SOCK_STREAM, $protocol) or die "socket() faile +d: $!"; setsockopt(SERVER,SOL_SOCKET,SO_REUSEADDR,1) or die "Can't set SO_R +EUSADDR: $!" ; my $my_addr = sockaddr_in($port,INADDR_ANY); bind(SERVER,$my_addr) or die "bind() failed: $!"; listen(SERVER,SOMAXCONN) or die "listen() failed: $!"; warn "Waiting for Files on $port\n"; } while (1) { while(my $remote_peer_addr = accept(PEERREG,PEERS)){ my ($peerport,$peeraddr) = sockaddr_in($remote_peer_addr); PEERREG->autoflush(1); my $newpeer = inet_ntoa($peeraddr); push (@servers, $newpeer); $servers = @servers; warn "We have $servers servers\n"; shutdown (PEERREG,2); } while (my $remote_addr = accept(FILESESSION,SERVER)){ my ($port,$hisaddr) = sockaddr_in($remote_addr); my $newclient = inet_ntoa($hisaddr); warn "Connection from $newclient\n"; FILESESSION->autoflush(1); my $length_of_randomstring=8; my @chars=('a'..'z','A'..'Z','0'..'9','_'); my $random_string = ""; foreach (1..$length_of_randomstring) {$random_string.=$chars[rand @chars];} $response = $random_string."\n"; print FILESESSION $response; open NEWFILE, ">splits/$random_string"; binmode(NEWFILE); print NEWFILE <FILESESSION>; close(NEWFILE); shutdown(FILESESSION,2); } }

In reply to Re^2: Two Sockets One Script by donkeylabor
in thread Two Sockets One Script by donkeylabor

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.