in reply to How to Multiplex a Client using IO::Select
Things get complicated fast, if you want a bidirectional client that connects to multiple servers simultaneously. See Simple bi-directional forking commandline client for a single connect client. You could do probably it with select, but it will involve a complex while loop check like this:
The complexity will get so great, that you are better off using an eventloop system to watch your sockets, like POE or Tk or Gtk2. POE may have something already in it's cookbook, google for it. Look at the Tk client in Simple threaded chat server , it uses fileevent (similar to select) and it would be easy to extend to multiple server connections.# very crude pseudocode my $select = IO::Select->new($server1); $select->add($server2); $select->add(/*STDIN); #for sending # etc etc my @ready; while(@ready = $select->can_read) { my $socket; for $socket (@ready) { # see if you can read a socket ..... ..... } #see if $select handle is STDIN, if so, send it to all in @ready } # do socket close error checking here
|
|---|