in reply to trying to write simple sockets client on Windows
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: trying to write simple sockets client on Windows
by Anonymous Monk on Apr 14, 2004 at 06:03 UTC | |
|
Re^2: trying to write simple sockets client on Windows
by Anonymous Monk on Apr 14, 2004 at 05:34 UTC |