I am sending data to the specified port, but nothing is being printed to screen. What am I missing? Am I just completely off?
I am attempting to be able to send data from multiple clients to a single server and have the data sent printed to screen.
Thanks!
#!/usr/bin/perl -lw # # # Define Modules use IO::Socket; use IO::Select; #Establish Server Socket $main_sock = new IO::Socket::INET (LocalHost => 'C285', LocalPort => 9325, Proto => 'tcp', Listen => 5, Reuse => 1 ); die "Socket could not be created. Reason: $!" unless $main_sock; #Process Received Data $readable_handles = new IO::Select(); $readable_handles->add($main_socket); while (1) { # Select() blocks until a socket is ready to be read ($new_readable) = IO::Select->select($readable_handles, undef, und +ef, 0); # If it comes here, there is atleast one handle # to read from. foreach $sock (@$new_readable) { if ($sock == $main_socket) { $new_sock = $sock->accept(); # Add to the list, and go back to select because the # new socket may not be readable yet. $readable_handles->add($new_sock); } else { # It is an ordinary client socket, ready for reading. $buf = <$sock>; if ($buf) { print $buf; } else { # Client closed socket. Need to do the same thing # here and remove it from $readable_handles list. print "Position = 6\n"; $readable_handles->remove($sock); clost($sock); } } } }
In reply to Multiplexing using Select by matt.schnarr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |