I presume this is the sort of thing you want (this is a server that accepts conns and listens/writes to them all asyncronously) but a client would be similar. It is not entirely clear what you actually want to do:

use IO::Select; use IO::Socket; $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080); $sel = new IO::Select( $lsn ); while(@ready = $sel->can_read) { foreach $fh (@ready) { if($fh == $lsn) { # Create a new socket to handle more conns $new = $lsn->accept; $sel->add($new); # register it with IO::Select } else { # Process socket my $data = <$fh>; if ( $data =~ m/exit/i ) { print $fh "Sayonara!\n"; $sel->remove($fh); $fh->close; } else { print $fh "Hello $data\n"; } } } }

Run the server in a command window. Open any number of other command windows and telnet localhost 8080 Talk to the server and it will talk back to that telnet session until you type exit.

cheers

tachyon


In reply to Re: trying to write simple sockets client on Windows by tachyon
in thread trying to write simple sockets client on Windows by Anonymous Monk

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.