Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi keszler
# The ##

package Server; use IO::Socket; use IO::Select; use strict; sub new { my $class = shift; my %args = @_; my $self = { parentWnd => $args{parentWnd} }; bless $self, $class; return $self; } sub initServer { my $self = shift; my $server = IO::Socket::INET::->new(Proto => 'tcp', LocalPort => 55555, Listen => 1, Reuse => 1 ) or die "Server can't start: $!" +; my $readable_handles = new IO::Select(); $readable_handles->add($server); my $buf; while (1) { # select() blocks until a socket is ready to be read or written my ($new_readable) = IO::Select->select($readable_handles, undef, undef, 0); # If it comes here, there is at least one handle # to read from or write to. For the moment, worry only about # the read side. foreach my $sock (@$new_readable) { if ($sock == $server) { my $new_sock = $sock->accept(); # Add it to the list, and go back to select because the # new socket may not be readable yet. print "Adding it \n"; $readable_handles->add($new_sock); } #- server part else { #print STDERR "Reading...\n"; print "Reading...$sock \n"; # It is an ordinary client socket, ready for reading. $buf = <$sock>; if ($buf) { #- print the buffer print "Read $buf\n"; # .... Do stuff with $buf } else { # Client closed socket. We do the same here, and remove # it from the readable_handles list print "removing it \n"; $readable_handles->remove($sock); close($sock); } } } } } 1;
## the ###
package Client; use IO::Socket; sub new { my $class = shift; my %args = @_; my $self = { parentWnd => $args{parentWnd} }; bless $self, $class; return $self; } sub initClient { my $self = shift; my $client = IO::Socket::INET::->new( Proto => 'tcp', PeerAddr => 'localhost', PeerPort => 55555 ) or die "Client can't connect: $!"; my @msgs = 1 .. 10; for (@msgs) { print $client "$_\n"; sleep 1; } } 1;

In reply to Re^2: tk mainwindow not appearing by simonz
in thread tk mainwindow not appearing by simonz

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (6)
    As of 2017-04-29 18:36 GMT
    Find Nodes?
      Voting Booth?
      I'm a fool:

      Results (534 votes). Check out past polls.